I believe that I have followed the tutorial completely, but when I click the "Trash It" link, the page reloads to the same @doc
page without any change.
Have a look at the code and let me know what needs to change.
DELETE is a listed verb under the rake routes
for docs#destroy
.
Thanks so much for the help!
show.html.haml:
%h1= @doc.title
%p= @doc.content
= link_to "All Docs", docs_path
= link_to "Fix Docs", edit_doc_path(@doc)
= link_to "Trash It", doc_path(@doc), method: :delete, data: { confirm: "Are you Sure?" }
docs_controller.rb:
class DocsController < ApplicationController
before_action :find_doc, only: [:show, :edit, :update, :destroy]
def index
@docs = Doc.all.order("created_at DESC")
end
def show
end
def new
@doc = Doc.new
end
def create
@doc = Doc.new(doc_params)
if @doc.save
redirect_to @doc
else
render 'new'
end
end
def edit
end
def update
if @doc.update(doc_params)
redirect_to @doc
else
render 'edit'
end
end
def destroy
@doc.destroy
redirect_to docs_path
end
private
def find_doc
@doc = Doc.find(params[:id])
end
def doc_params
params.require(:doc).permit(:title, :content)
end
end
Rails.application.routes.draw do
get 'welcome/index'
root 'welcome#index'
resources :docs
end