Ruby on rails 4 仅为嵌套的_属性显示一个表单
我只想为用户和约会之间的一对多关系显示一个嵌套表单。用户只能创建一个约会,表单应仅显示一个约会的字段,无论他有多少约会 我试过:限制选项Ruby on rails 4 仅为嵌套的_属性显示一个表单,ruby-on-rails-4,limit,nested-attributes,Ruby On Rails 4,Limit,Nested Attributes,我只想为用户和约会之间的一对多关系显示一个嵌套表单。用户只能创建一个约会,表单应仅显示一个约会的字段,无论他有多少约会 我试过:限制选项 class User has_many :appointments, dependent: :destroy accepts_nested_attributes_for :appointments, limit: 1 end 我还尝试限制控制器中内置的约会数量 class UsersController def edit @user =
class User
has_many :appointments, dependent: :destroy
accepts_nested_attributes_for :appointments, limit: 1
end
我还尝试限制控制器中内置的约会数量
class UsersController
def edit
@user = current_user
1.times { @appointment = @user.appointments.build }
end
end
对于用户的每次约会,我都会得到一个嵌套表单,再加上一个额外的嵌套表单。我知道我可以将这种关系更改为一对一,但这是针对遗留代码的,而且这种关系在将来很可能是一对多的
是否有一种方法,无论用户有多少约会,我都只能显示一个嵌套表单