Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 仅为嵌套的_属性显示一个表单_Ruby On Rails 4_Limit_Nested Attributes - Fatal编程技术网

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
对于用户的每次约会,我都会得到一个嵌套表单,再加上一个额外的嵌套表单。我知道我可以将这种关系更改为一对一,但这是针对遗留代码的,而且这种关系在将来很可能是一对多的

是否有一种方法,无论用户有多少约会,我都只能显示一个嵌套表单