delete_job_listings.step

goals do

  goal "Remove a job  -  Let's add a way to delete postings."

end

message <<-MARKDOWN

  # Postings be gone!

   Once a job is filled, we don't want a listing for it hanging out forever.

  If we look at our [handy Routes page](http://localhost:3000/rails/info/routes), we see this:
MARKDOWN

source_code :html, "job_path   DELETE   /jobs/:id(.:format)   jobs#destroy"

steps do
  step  "Send DELETE" do

    message "So we need to send the DELETE http verb to the server, so we can get to the destroy method on the jobs controller (that we will make soon). It turns out rails link_to helpers accept specific verbs as an argument. "

    source_code_with_message "Add this line below the edit posting link in `index.html.erb`", :erb, "  <h5><%= button_to 'Delete Posting', job, method: :delete %></h5>"

    message "Go to the index, and try to delete something."

    error_box "The action 'destroy' could not be found for JobsController"

    message "This is like my favorite error now!"

  end
  step "add the destroy method" do

    source_code :ruby,
    <<-RUBY
      def destroy
      end
    RUBY

    message <<-MARKDOWN
      This fixes the error. But just like updating, we still need to add the logic that actually deletes the job.

      See if you can figure out the right syntax for finding the job, deleting it, and then redirecting to a useful page.

      **Don't scroll down!!!**
    MARKDOWN

    message <<-MARKDOWN
    * here
    * is
    * even
    * more
    * strategic
    * white
    * space
    * so
    * the
    * answer
    * isn't
    * immediately
    * visible!

    Okay, here's the answer:
    MARKDOWN

    source_code :ruby,
    <<-RUBY
      @job = Job.find(params[:id])
      @job.destroy
      redirect_to jobs_path
    RUBY

    message "Try it again, and... kablammo! We're destroying job listings left and right!"

  end
end

commitnow

next_step "add_more_things"