url for - Rails: generate URL from class name and ID -


so, i've got situation have big array includes references objects like:

array=[['vendor',1],['comment',2]] 

i'd able create link objects in array. seems me since know class name , id should able generate link, far haven't figured out how without instantiating object.

i know do:

array.each |i|   = link_to i[0].constantize.find(i[1]) end 

... that's tons of overhead. suggestions on how build link class name string , id?

you use inflections , dynamically compute path helper :

array.each |i|   = link_to 'show', send( "#{i[0].underscore}_path", i[1] ) end 

but won't work if have nested or namespaced resources.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -