I have a model Member
that has a new creation form. The form allows users to assign a department and position for each member to be a part of. The positions are relative to the department. In a separate part of the app, users can create departments and create/assign positions. I am trying to create a grouped_collection_select for the new members page, however my positions are not showing up, just departments as categories. I believe this is an association issue, where the positions are not being associated with their respective dept. I have the string department_id
in my positions model, however I don't think the selection is able to read that as the parent. If anyone can point me in the correct direction that'd be awesome.
The line giving an error: (from the new members form_for
)
<%= f.grouped_collection_select :title, Department.where(production_id: current_user.default_working_production_id).order(:department), :positions, :department, :id, :position, include_blank: true %>
My schema looks like:
create_table "departments", force: true do |t|
t.string "department"
t.datetime "created_at"
t.datetime "updated_at"
t.string "production_id"
end
create_table "positions", force: true do |t|
t.string "position"
t.string "department_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "production_id"
end
My model associations:
class Member < ActiveRecord::Base
belongs_to :company
validates :firstname, presence: true
validates :email, presence: true
def name
"#{firstname} #{lastname}"
end
end
class Department < ActiveRecord::Base
has_many :positions
attr_accessible :department
validates :department, presence: true
end
class Position < ActiveRecord::Base
belongs_to :department
attr_accessible :department_id, :position, :department
end
Aucun commentaire:
Enregistrer un commentaire