Rails 4 - Many to many relationship -


i have bookmark model. have list model. users can create bookmark lists.

i've created list scaffold command

rails generate scaffold list title:string 
  1. a list can have many bookmarks
  2. a bookmark can have many lists

can me create list bookmark relationship.?

it awesome if can give me resources learn.

update:

  1. a bookmark can have many lists

lets bookmarked http://stackoverflow.com. , have 2 lists like:

  1. programming help
  2. favorite sites

then should able add bookmark both lists.

so guess a bookmark can have many lists valid statement.

applicable => rails 4:

app/model/bookmark.rb

class bookmark < activerecord::base   has_and_belongs_to_many :lists end 

app/model/list.rb

class list < activerecord::base   has_and_belongs_to_many :bookmarks end 

create new migration

rails generate migration createjointablelistbookmark list bookmark 

migrate

rake db:migrate 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -