Skip to content

Instantly share code, notes, and snippets.

@pullmonkey
Created August 11, 2012 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pullmonkey/3319683 to your computer and use it in GitHub Desktop.
Save pullmonkey/3319683 to your computer and use it in GitHub Desktop.
dynamic select models
# app/models/artist.rb
class Artist < ActiveRecord::Base
belongs_to :genre
has_many :songs
attr_accessible :genre_id, :name, :genre
end
# app/models/genre.rb
class Genre < ActiveRecord::Base
attr_accessible :name
has_many :artists
has_many :songs, :through => :artists
end
# app/models/songs.rb
class Song < ActiveRecord::Base
belongs_to :artist
attr_accessible :artist_id, :title, :artist
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment