0
我创建了嵌入2个隔离引擎的rails(4)应用程序。其中一个引擎定义了一个针对主应用程序和第二个引擎中的模型的多态关联。如何创建未知的rails引擎多态记录的url路径?
module Engine1
class Engine1Model < ActiveRecord::Base
belongs_to :testable, polymorphic: true
end
end
module Engine2
class Engine2Model < ActiveRecord::Base
end
end
class MainAppModel < ActiveRecord::Base
end
在Engine1ModelsController视图(show/index)中,我想创建一个指向关联模型的链接。当你知道从哪个域来记录,你可以这样做:
polymorphic_path([main_app, record1.testable])
或
polymorphic_path([engine2, record2.testable])
但这里的问题是,我不知道该模型的起源。我如何创建一个有效的网址路径?
这也许是一个答案'发送的开始(record.testable.class.name.deconstantize.underscore).polymorphic_path(record.te稳定)'但它如果引擎使用'as:'选项挂载,将无法工作... – Gregory