为什么摧毁行动不被解雇?

joh*_*doe 2 ruby-on-rails

我正在使用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动作.我不知道为什么会这样?

Rya*_*igg 5

link_to应该这样:

<%= link_to "Delete", @article, :method => :delete, :confirm => "are u sure?" %>
Run Code Online (Sandbox Code Playgroud)

这将为您的文章生成正确的URL并转到该destroy操作.