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