How to create a url path to an unknown rails engine polymorphic record? -


i created rails (4) application embeds 2 isolated engines. 1 of engine defines polymorphic association targets models in main application , second engine.

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 

in engine1modelscontroller views (show/index) create link associated model. when know domain come record can that:

polymorphic_path([main_app, record1.testable]) 

or

polymorphic_path([engine2, record2.testable]) 

but here issue don't know origin of model. how can create valid url path?

i created helper:

module engine1   module applicationhelper     def external_polymorphic_path(record)       engine_name = record.class.name.deconstantize.underscore       engine_name = 'main_app' if engine_name.empty?       send(engine_name).polymorphic_path(record))     end   end end 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -