hey guys, i am new to rails, so please be nice to me if i ask stupid
questions.
I ran into this problem as I try to play with many to many
association.
I have three objects,
Category
has_many :artist, :through => artist_category
has_many :artist_category
Artist
has_many :category, :through =>artist_category
hash_many :artist_category
attr_accessor :category_ids
after_save :update_category
def update_category
unless category_ids.null?
self.artist_category.each do |m|
m.destory unless category_ids.include?(m.category_id.to_s)
category_ids.delete(m.category_id.to_s)
end
category_ids.each do |g|
self.category_artist.create(:category_id => g) unless
g.blank?
end
reload
end
end
Artist_Category
belongs_to: category
belongs_to: artist
============ on the artists_controller, i have new and create method