Ruby on rails rails应用程序中的下拉错误

Ruby on rails rails应用程序中的下拉错误,ruby-on-rails,ruby,drop-down-menu,Ruby On Rails,Ruby,Drop Down Menu,我使用的是rails 5和ruby 2.2.2 模型:: 视图::_form.html.erb在照片中 但我得到了这个错误: 我认为office没有直接连接到photo,这就是为什么会出现此错误的原因。我在模型中尝试了穿透,但仍然出现错误 我如何解决这个问题 谢谢。您正在呼叫表单对象照片上的帮助者 试试,集合\u单数\u ID方法您可以发布照片模型的表结构吗?它不适用于meI am使用f进行两个集合\u选择。那只是个打字错误。办公室不能在照片模型中。因为照片通过员工属于办公室。它们之间没有直接

我使用的是rails 5和ruby 2.2.2

模型:: 视图::_form.html.erb在照片中 但我得到了这个错误:

我认为office没有直接连接到photo,这就是为什么会出现此错误的原因。我在模型中尝试了穿透,但仍然出现错误

我如何解决这个问题


谢谢。

您正在呼叫表单对象照片上的帮助者


试试,集合\u单数\u ID方法您可以发布照片模型的表结构吗?它不适用于meI am使用f进行两个集合\u选择。那只是个打字错误。办公室不能在照片模型中。因为照片通过员工属于办公室。它们之间没有直接联系。
class Office < ApplicationRecord
  has_many :employees
end

class Employee < ApplicationRecord
  belongs_to :office
  has_many :photos
end

class Photo < ApplicationRecord
  belongs_to :employee
end
<div class="field">
  <%= f.label :office %>
  <%= f.collection_select(:office_id, Office.all, :id, :name) %>
</div>

<div class="field">
  <%= f.label :employee %>
  <%= collection_select(:employee_id, Employee.all, :id, :name) %>
</div>     

<div class="field">
  <%= f.label :photo %>
  <%= collection_select(:photo_id, Photo.all, :id, :name) %>
</div>     

<div class="actions">
  <%= f.submit %>
</div>
<%= f.collection_select(:office_id, Office.all, :id, :name) %>
<%= collection_select(:employee_id, Employee.all, :id, :name) %>
<%= collection_select(:photo_id, Photo.all, :id, :name) %>