activerecord - Rails 4 path_to Active Record object of unknown type -


link_to cleverly figure out type active record object , create link it's show route. how can find path unknown object type. ie. i'd like

<div id="target_path" data-path="<%= path_to @my_polymorphic_instance %>" ></div> 

implementing might like

def path_to obj   url_for( :controller => obj.class.to_s.underscore.pluralize,            :action => :show,            :id => obj.to_param,            :only_path => true ) end 

whats better way?

the polymorphic_path should trick:

<div id="target_path" data-path="<%= polymorphic_path @my_polymorphic_instance %>" ></div> 

in fact, it's source code similar path_to supposition.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -