Update Job Listings
Goals
Steps
Step 1: Add the edit page
edit_job_path GET /jobs/:id/edit(.:format) jobs#editError! Woo!!!
The action 'edit' could not be found for JobsController
Step 2: add the edit action to the JobsController
def edit @job = Job.find(params[:id]) endDiscussion: Params
Error! Woo!!!
JobsController#edit is missing a template for request formats: text/html
Step 3: add a view
<h1>Edit Posting</h1>Step 4: plan the update form
Discussion: Don't Repeat Yourself (DRY)
Step 5: create a partial for the form
<%= form_with(model: @job, local: true) do |form| %> <div> <%= form.label :title %> <%= form.text_field :title %> </div> <div> <%= form.label :description %> <%= form.text_area :description, size: '60x6' %> </div> <div> <%= form.submit %> </div> <% end %><%= render "form" %>
Step 6: re-use the partial
<%= render "form" %>
Step 7: Actually Update The Job
Error! Woo!!!
The action 'update' could not be found for JobsController
Step 8: Add the update action to the JobsController
def update enddef update redirect_to jobs_path endDiscussion: What is this controller method missing?
def update @job = Job.find(params[:id]) @job.update(job_params) redirect_to jobs_path endStep 9: Add a Link
<% @jobs.each do |job| %> <h3><%= job.title %></h3> <p><%= job.description %></p> <h5><%= link_to "Edit Posting", edit_job_path(job)%></h5> <% end %>
Now would be a good time to commit to git
Next Step:
Go on to Delete Job Listings