【发布时间】:2011-08-03 06:39:15
【问题描述】:
是否有一种简单直接的方法可以在视图中提供链接以在资源不存在时创建资源或在资源存在时编辑现有资源?
IE:
User has_one :profile
目前我会做类似...
-if current_user.profile?
= link_to 'Edit Profile', edit_profile_path(current_user.profile)
-else
= link_to 'Create Profile', new_profile_path
如果这是唯一的方法,这没关系,但我一直在尝试看看是否有“Rails Way”来做类似的事情:
= link_to 'Manage Profile', new_or_edit_path(current_user.profile)
有什么好干净的方法来做这样的事情吗?类似于Model.find_or_create_by_attribute(....) 的视图
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 new-operator edit link-to