I have these models:
class App < ActiveRecord::Base
has_many :inventories
has_many :products, through: :inventories
end
class Inventory < ActiveRecord::Base
belongs_to :app
belongs_to :product
default_scope { order('position ASC') }
end
class Product < ActiveRecord::Base
has_many :inventories
has_many :apps, through: :inventories
end
My goal is to be able to add products to apps and keep them in order. I have a position field on my inventories to keep track of the order. My implementation so far is to use <select>
's to list all the available products. I am also using cocoon to dynamically add and remove products.
I’m struggling to wrap my head around what parameters I need to accept (via strong_parameters) and how to format the view so they will be accepted/retrieved correctly from the database. I’m happy to post more code, I’m just very far down a few rat holes.
Any suggestions?