I have two models, say UserandGroup
I know that I can access the show action for each object using different solutions:
# PATH
link_to user.name, user_path(user)
link_to group.name, group_path(group)
# URL
link_to user.name, user_url(user)
link_to group.name, group_url(group)
But the magic of Rails comes when
# PATH
link_to user.name, user_path(user)
link_to group.name, group_path(group)
# is equivalent to
# PATH
link_to user.name, user
link_to group.name, group
Is there a way I can interpolate to get the url?
I could write something like this:
link_to user.name, send("#{user.class.name.downcase}_url", user)
But is there a cleaner way?
source
share