Dynamically generating method names in rails
- by badnaam
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