【发布时间】:2016-10-25 20:11:29
【问题描述】:
我相信我已经完全按照教程进行操作,但是当我单击“垃圾箱”链接时,页面会重新加载到相同的 @doc 页面,而没有任何更改。
查看代码,让我知道需要更改的内容。
DELETE 是rake routes 下列出的动词,用于docs#destroy。
非常感谢您的帮助!
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
【问题讨论】:
-
请为这个控制器发布你的 routes.rb 配置。
-
Rails.application.routes.draw 确实得到 'welcome/index' 根 'welcome#index' 资源 :docs end
-
您在什么环境下运行您的应用程序?开发/测试/产品?
-
开发。它仅在本地运行。
-
你用的是什么版本的rails?
标签: ruby-on-rails ruby ruby-on-rails-4