Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Movie < ActiveRecord::Base
- has_many :genreships
- has_many :genres, through: :genreships
- accepts_nested_attributes_for :genres, :reject_if => :all_blank, :allow_destroy => true
- accepts_nested_attributes_for :genreships, :reject_if => :all_blank, :allow_destroy => true
- end
- class Genreship < ActiveRecord::Base
- belongs_to :movie
- belongs_to :genre
- accepts_nested_attributes_for :genre, :reject_if => :all_blank
- end
- class Genre < ActiveRecord::Base
- has_many :genreships
- has_many :movies, through: :genreships
- end
- = simple_form_for @movie do |f|
- .field
- = f.input :title
- .field
- = f.input :release_date, label: 'Release Date', order: [:month, :day, :year], start_year: 1901
- .field
- = f.input :summary, as: :text
- #genres
- = f.simple_fields_for :genreships do |genreship|
- = render 'genreship_fields', :f => genreship
- | #{link_to_add_association 'add a genre', f, :genreships} | #{link_to_add_association 'create a new genre', f, :genres}
- .actions = f.submit 'Save', class: 'btn btn-default'
- .nested-fields
- #genre_from_list
- = f.association :genre, :collection => Genre.order(:name), :prompt => 'Choose an existing genre'
- = link_to_remove_association "remove genre", f
- .nested-fields
- = f.input :name
- = link_to_remove_association "remove form", f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement