Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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 属于父窗体,在Rails 3中有许多嵌套窗体_Ruby On Rails_Ruby On Rails 3_Nested Forms - Fatal编程技术网

Ruby on rails 属于父窗体,在Rails 3中有许多嵌套窗体

Ruby on rails 属于父窗体,在Rails 3中有许多嵌套窗体,ruby-on-rails,ruby-on-rails-3,nested-forms,Ruby On Rails,Ruby On Rails 3,Nested Forms,缩略型号: class Event < ActiveRecord::Base belongs_to :place accepts_nested_attributes_for :place end class Place < ActiveRecord::Base has_many :events end 简略视图: <%= form_for(@event) do |f| %> <%= fields_for @event.place do |pl

缩略型号:

class Event < ActiveRecord::Base
  belongs_to :place
  accepts_nested_attributes_for :place  
end

class Place < ActiveRecord::Base
  has_many :events  
end
简略视图:

<%= form_for(@event) do |f| %>
<%= fields_for @event.place do |place_f| %>

鉴于上述情况…… 我希望用户能够创建一个事件。当他们创建事件时,他们可以选择添加地点。数据库中可能存在也可能不存在该位置

现在,提交表单时没有关联或创建位置,但它肯定在post参数中


有没有想过我做错了什么?这是针对Rails 3的。

如果您不想让用户填充位置属性,请从控制器中的
新操作中删除
@event.build\u place

def new
  @event = Event.new
end
并从视图中删除

def new
  @event = Event.new
end