Dynamically generating method names in rails

Posted by badnaam on Stack Overflow See other posts from Stack Overflow or by badnaam
Published on 2010-06-14T22:06:51Z Indexed on 2010/06/14 22:12 UTC
Read the original article Hit count: 133

Filed under:

I need to generate links in my views using the url helpers such as user_path(@user), the catch is, in some cases I don't know what model I am creating this link for i.e. whether it is a user or a store or someting else

I would like to be able to determine this on the fly and call the appropriate view helper, currently I am doing the following, but I am wondering if there is a drier way of doing it.

if object.class == "Store" store_path(object) elsif object.class == "User" user_path(object) ...etc

© Stack Overflow or respective owner

Related posts about ruby-on-rails