也许我是愚蠢的,但Rails提供了生成的URL像这样这个漂亮的语法:传:新的Rails url_for
url_for([user, comment]) # => /users/1/comment/1
传递:edit
允许我创建这样的事情:
url_for([:edit, user, comment]) # => /users/1/comment/1/edit
但是有什么方法可以跟踪?
url_for([:new, user, comments]) # => NoMethodError: undefined method `new_user_comments_url'
UPDATE:增加了更多的信息。
我的routes.rb:
resources :users do
resources :comments
end
resources :posts do
resources :comments
end
我在这里的问题是,我不能使用Rails的自动生成的URL帮手(user_comments_url
),因为我分享观点既为用户的意见和交注释。
有两种解决方法(但没有人感觉就像“导轨”三通),用于我的问题:
添加逻辑视图,例如一些条件。
定义我自己的网址助手,如
new_parent_comment(user_or_blog)
。
增加了更多信息。 – 2012-04-13 21:07:49