Dynamically generating method names in rails -


Using URL helpers like user_path (user) I need to generate links in my thoughts, hold something in I do not know what the model I am creating for this link i.e. this is a user or a store or something

I want to be able to set it on the fly and make proper visual calls Assistant, I currently have the following I am, but I think that is a dry way of doing this.

  if object.class == "store" store_ path (object) elsif object.class == "user" user_path (object) ... etc  
< / Div>

What do you want:

If you have any choice as a parameter instead of a hash If you pass a record (such as an active record or active resource), you will trigger the designated path for that record. Lookup will be on the name of the class. Therefore, passing the workshop object will try to use the workshop_path route.

If you are using, you can pass the object as the URL:

  & lt;% = link_to 'title', Object% & gt;  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -