urlhelper - In Rails, what's the URL helper for an unknown model? -


i'm trying path in rails model don't know class of in rake task (so it's not in .erb).

i know can this:

rails.application.routes.url_helpers.<model>_path(model) 

but if don't know model? seems not rails-y switch on model.class or other such inspection. i'm looking default path or url model.

edit: clarify mean default path, it's href when link_to; i.e., can this:

<%= link_to "my model", @model %> 

without specifying url helper model_path. that's i'm looking for.

internally, link_to calls url_for path given arguments.

if call url_for model, it'll forward further polymorphic_path or polymorphic_url.

so should work, if want path

task :some_task => :environment   include rails.application.routes.url_helpers    # ...    path  = polymorphic_path(some_model_instance) # => e.g. "/widgets/42" end 

you can use url_for, you'll have define :host option. see here more


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -