destroy的链接返回“未定义的方法”

时间:2012-07-01 22:15:35

标签: ruby-on-rails crud

我有* 主题 *控制器,并在view/topics/index.html.erb链接中销毁项目:

<%= link_to 'Destroy',topic, confirm: 'Are you sure?', method: :delete %>

我也尝试了

<%= link_to 'Destroy', topic_path(topic), confirm: 'Are you sure?', method: :delete %>

但两者都返回

  

类的未定义方法topic_path:0x00000105056a80&gt;:   0x00000105047328&GT;

routes.rb 中的

如下:

  namespace :admin do
    ...
    resources :topics
  end

哪里可能是问题以及如何以简单的方式解决它?我正在通过CRUD检查其他生成的控制器/视图,并且设置始终是相同的,并且在所有其他控制器中它运行良好,就在这一个我反复出现这个错误。

1 个答案:

答案 0 :(得分:3)

试试这个:

<%= link_to 'Destroy', admin_topic_path(topic), 
                                    confirm: 'Are you sure?', method: :delete %>

要确保运行命令rake routes,请在结果中看到您的路线。