Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/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 韩元和x27的轨道字段;我看不到我的领域在里面_Ruby On Rails_Ruby_Ruby On Rails 3_Nested Forms - Fatal编程技术网

Ruby on rails 韩元和x27的轨道字段;我看不到我的领域在里面

Ruby on rails 韩元和x27的轨道字段;我看不到我的领域在里面,ruby-on-rails,ruby,ruby-on-rails-3,nested-forms,Ruby On Rails,Ruby,Ruby On Rails 3,Nested Forms,我试图同时创建两个对象。我所拥有的最好的方法是使用字段。而且这种关系有很多 model/location.rb attr_accessible :address, :customer_id, :event_id, :latitude, :longitude belongs_to :customer belongs_to :event model/event.rb attr_accessible :locations_attributes has_many :location

我试图同时创建两个对象。我所拥有的最好的方法是使用字段。而且这种关系有很多

model/location.rb

  attr_accessible :address, :customer_id, :event_id, :latitude, :longitude
  belongs_to :customer
  belongs_to :event
model/event.rb

  attr_accessible :locations_attributes
  has_many :locations, :dependent => :destroy
  accepts_nested_attributes_for :locations
表格如下:

<%= form_for(@event) do |f| %>
  ...
  <%= f.fields_for :locations do |e| %>
    <%= e.text_field :longitude %>
    <%= e.text_field :latitude %>
  <% end %>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
错误是这样的

app/controllers/events_controller.rb:60:in `new'
app/controllers/events_controller.rb:60:in `create'
line 60: @event = Event.new(params[:event])
我的控制器是这样的

app/controllers/events_controller.rb:60:in `new'
app/controllers/events_controller.rb:60:in `create'
line 60: @event = Event.new(params[:event])

您应该在表单中完成此操作:(位置而不是位置)


在您的model event.rb中


attr\u accessible:description,:title,:locations\u attributes
(locations not location)

您应该以您的形式执行此操作:(location not locations)


在您的model event.rb中


attr\u accessible:description,:title,:locations\u attributes
(locations not location)

正如您所说,它应该是
not
:locations
为什么您不能修复它?因为我收到一个错误,无法批量分配,如果我查看文档,它还声明让它plurialsadd location_属性到model我只是尝试并得到这个错误仍然无法批量分配受保护的属性:location。我更新了一些东西更新了Khaled说的话???正如你所说的,应该是
而不是
:位置
为什么你不能修复它?因为我得到了一个错误,不能批量分配,如果我查看文档,它还声明让它plurialsadd location_属性到model我只是尝试并得到这个错误仍然无法批量分配受保护的属性:location。我更新了一些东西更新了Khaled说的话????