建设有一个的has_many多态模型控制器路径
-
21-09-2019 - |
题
我有可以与许多类型的commentables的多态模型的评论。 在我的击溃,例如我有:
map.resources :newsitems do |news|
news.resources :comments
end
一切正常,唯一的问题是产生的路径。 我在我的意见/控制器@commentable项目,我从一个的before_filter检索。
链接到[@commentable,@comment]工作正常,像形式,显示,或破坏。 但新的和编辑链接搞乱... comments_path(@commentable,@comment)不起作用例如
我怎么能在我的观点建立这个动态路径?
特别是edit_和new_路径
解决方案
我用polymorphic_path为此,这需要:行动:新的和:编辑,像这样:
link_to("New Comment", polymorphic_path([@commentable,@comment], :action => :new))
http://api.rubyonrails.org/classes/ActionController/PolymorphicRoutes。 HTML#M000487
不隶属于 StackOverflow