0

I have a quick question concerning join tables and multiple selections on a form.

I have two models in a Rails App (4.0), one is called Skills, and the other, Opportunity. An opportunity can have many skills associated with it, and a skill can be associated with many opportunities.

Because of that type of relationship I created a join table called Opportunity_Skills. This table just has skill_id, and opportunity_id.

Here are my associations written out:

class Skill < ActiveRecord::Base
  has_many :opportunity_skills
  has_many :opportunities, through: :opportunity_skills
end


class Opportunity < ActiveRecord::Base
  has_many :opportunity_skills
  has_many :skills, through: :opportunity_skills

  accepts_nested_attributes_for :opportunity_skills
end


class OpportunitySkill < ActiveRecord::Base
  belongs_to :opportunity
  belongs_to :skill
end

I have created an opportunity 'new' page in order for users to create new opportunities. I would like users to be able to select multiple skills while creating a new opportunity. In order to make that happen I have made the Opportunity model accepted nested attributes for opportunity skills.

I can't figure out what I need on my form (using simple form) to make all of the different options show up as check boxes (the values in the skills table). Any ideas or suggestions would be great. If I left out any information and/or just plain didn't make sense please let me know and I can provide more details.

Thank you for the help in advance.

Cheers,

Graham

Jackson
  • 5,711
  • 5
  • 31
  • 41

1 Answers1

0

Sounds like your answer may be this railscast

andrewcockerham
  • 2,561
  • 3
  • 21
  • 19