我有基本的设置:
class Document < ActiveRecord::Base
belongs_to :documentable, polymorphic: true
end
class Contact < ActiveRecord::Base
has_many :documents, as: :documentable
end
class Case < ActiveRecord::Base
has_many :documents, as: :documentable
end现在,在“我的文档”视图的_index.html.erb中,我想做以下操作:
<%= link_to "New Document", polymorphic_path([:new, @documentable, Document.new]) %>其中@documentable将是联系人或案例的实例。
我希望上面的代码生成一个像new_contact_document_path这样的url,但是它只是尝试生成一个类似于new_documents_path的url。
我可能做错什么了?
发布于 2015-01-04 00:54:34
试一试
<%= link_to "New Document", new_polymorphic_path([@documentable, Document]) %>请注意这里与您发布的代码的两个不同之处:
Document而不是Document.new,这似乎是首选的方法有关更多详细信息,请参阅ActionDispatch文档。
https://stackoverflow.com/questions/27760154
复制相似问题