Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should be your classes:</p> <pre><code>class User &lt; ActiveRecord::Base has_and_belongs_to_many :skills end class Skill &lt; ActiveRecord::Base has_and_belongs_to_many :users end </code></pre> <p>and this is the migration which creates them</p> <pre><code>class CreateUsers &lt; ActiveRecord::Migration def self.up create_table :users do |t| t.string :name t.timestamps end end def self.down drop_table :users end end class CreateSkills &lt; ActiveRecord::Migration def self.up create_table :skills do |t| t.string :name t.timestamps end end def self.down drop_table :skills end end class SkillsUsers &lt; ActiveRecord::Migration def self.up create_table :skills_users, :id =&gt; false do |t| t.integer :skill_id t.integer :user_id end end def self.down drop_table :skills_users end end </code></pre> <p>then add a new skill is as simple as </p> <pre><code>user.skills &lt;&lt; Skill.find(1) # to add a skill user.skills = Skill.all # to add many of them </code></pre> <p>Look <a href="http://guides.rubyonrails.org/association_basics.html#the-has_and_belongs_to_many-association" rel="nofollow">here</a> fo further details</p> <p><strong>Update:</strong> I ve tried the autocomplete gem and I think you should accept the Rubish Gupta suggestion, i.e. use my models plus <a href="http://loopj.com/jquery-tokeninput/" rel="nofollow">jquery token input</a> because it will handle pretty well many-to-many associations. Autocomplete gem as far as I saw is for 1-to-n associations.</p> <p>Moreover you have a <a href="https://github.com/ryanb/railscasts-episodes/tree/master/episode-258" rel="nofollow">full working example</a> in rails to play with.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload