Rails - 路由改变了它自己的路线

时间:2015-08-22 01:28:54

标签: ruby-on-rails routes

昨天,我的表格中有这条线。

%p= link_to "Reply", comment_reply_path(comment), :method => :get, :remote => true

它工作正常。但是,今天当我启动我的rails网站时,我得到了一个未定义的方法错误,我不得不将我的代码更改为。

reply_comment_path(comment)

我的routes.rb包含

resources :comments, :only => [:create, :destroy] do
    get :reply, on: :member
end

知道为什么会这样吗?

1 个答案:

答案 0 :(得分:2)

这是因为昨天你有

#routes.rb
resources :comments, :only => [:create, :destroy] do
  get :reply
end

这将创建comment_reply的前缀,以便comment_reply_path(comment)正常工作。

但是现在,由于您添加了on: :member,因此前缀会更改为reply_comment,因此您应该使用reply_comment_path(comment)