我正在使用Rails 3并试图了解为什么Destroy动作没有被解雇!我的html被定义如下:
<%= link_to "Delete", :action => "destroy", :id => article, :method => :delete, :confirm => "are u sure?" %>
Run Code Online (Sandbox Code Playgroud)
这是ArticlesController:
def destroy
@article = Article.find(params[:id])
@article.destroy
respond_to do |format|
format.html { redirect_to articles_url }
end
end
Run Code Online (Sandbox Code Playgroud)
当我点击"删除"链接时,它会将我带到show动作.我不知道为什么会这样?
你link_to应该这样:
<%= link_to "Delete", @article, :method => :delete, :confirm => "are u sure?" %>
Run Code Online (Sandbox Code Playgroud)
这将为您的文章生成正确的URL并转到该destroy操作.
| 归档时间: |
|
| 查看次数: |
964 次 |
| 最近记录: |