0

I have the following form where a user selects a department from a list of database entries on the activity centers page. I am trying to display the department string (:department) instead of the department ID. I tried @activity_center.department.department but that isn't working. Any suggestions?

Form:

<%= f.select :department_id, options_from_collection_for_select(@departments, 'id', 'department'), hide_label: true, :multiple => false %>

Departments Model:

class Department < ActiveRecord::Base
    validates :department, :presence => true
    has_many :activity_centers
end

Activity Centers Model:

class ActivityCenter < ActiveRecord::Base
    validates :activity_center, :presence => true
    validates :department_id, :presence => true
    belongs_to :departments
end

Activity centers index page:

<% @activity_centers.each do |activity_center| %>
    <tr>
      <td><%= activity_center.activity_center %></td>
      <td><%= activity_center.department.department %></td>
      <td style="text-align:right;">
        <%= link_to 'View Activity Center',  activity_center_path(activity_center),      class: "btn btn-success btn-xs" %>
        <%= link_to 'Edit',           edit_activity_center_path(activity_center), class: "btn btn-default btn-xs" %>
        <%= link_to 'Delete',         activity_center_path(activity_center),      class: "btn btn-danger btn-xs",
            method: :delete,
            data: { confirm: 'Confirm you want to delete this activity_center.' } %></td>
    </tr>
  <% end %>
Dan Brookwell
  • 341
  • 2
  • 12

1 Answers1

0

Per MZaragoza it was a typo. belongs_to is supposed to be singular.

Dan Brookwell
  • 341
  • 2
  • 12