У меня есть две модели в отношении has_one Proper_to:
class Facility < ApplicationRecord
has_one :machine
end
class Machine < ApplicationRecord
belongs_to :facility
end
При создании новой машины у меня есть коллекция collection_select для сохранения объекта:
<%= collection_select(:machine, :facility_id, Facility.all, :id,
:facility_name, prompt: true) %>
На странице индекса, когда я пытаюсь перечислить все машины, я получаю сообщение об ошибке:
undefined method `facility_name'
Вот мой код:
<table class="table table-responsive table-striped table-bordered table-hover
table-sm ">
<thead>
<tr>
<th>Facility Name</th>
.
.
.
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @machines.each do |machine| %>
<tr>
<td><%= machine.facility.facility_name %></td>
.
.
.
<td><%= link_to 'Show', machine %></td>
<td><%= link_to 'Edit', edit_machine_path(machine) %></td>
<td><%= link_to 'Destroy', machine, method: :delete, data: { confirm:
'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
Как мне избавиться от ошибки?