I have a the following models:
class Release < ActiveRecord::Base
has_many :products, :dependent => :destroy
has_and_belongs_to_many :tracks
end
class Product < ActiveRecord::Base
belongs_to :release
has_and_belongs_to_many :tracks
end
class Track < ActiveRecord::Base
has_and_belongs_to_many :releases
has_and_belongs_to_many :products
end
At the moment when I create a Release I can assign tracks to it. When I create a product (under a release) I want it to inherit the tracks assigned to it but be able to amend the order, add and remove tracks.
The reasoning behind this approach is that in most circumstances the tracks will be the same across multiple products so it saves work having to re-list/upload tracks. I could simply pull in tracks from the release, but I must have the facility to alter this, for example there could be an iTunes exclusive with bonus track.
I’m guessing I need to add some lines to the new & create actions of the Product controller to facilitate this? Can anyone offer some guidance?
In the scenario that an extra track not added at release level is later added at product level, how would I make sure it’s included at release level as well?
Would a Jquery drag and drop Release to Product approach be best?
So you could do something as follows:
This way you should always have a list of the original tracks that came with the release, and you have a list of the tracks that are associated with the proudct. Now you can add and remove tracks from the product and always have an idea of which came with the original release.
Hope this helps.