Is there a simple and easy way to provide a link in a view, to create a resource if it does not exist or to modify an existing one if there is one?
IE:
User has_one :profile
Currently, I will do something like ...
-if current_user.profile? = link_to 'Edit Profile', edit_profile_path(current_user.profile) -else = link_to 'Create Profile', new_profile_path
This is fine if this is the only way, but I tried to see if there is a βRails Wayβ way to do something like:
= link_to 'Manage Profile', new_or_edit_path(current_user.profile)
Is there a good clean way to do something like this? Something like the equivalent of the view Model.find_or_create_by_attribute(....)
new-operator ruby-on-rails ruby-on-rails-3 edit link-to
Andrew
source share