I have two models. Deals and Stores. I want to add already created Deals when creating a Store. I want to add already created Sores when creating a Deal. I am trying to use f.has_many, but I can't make it working.
My relationship is built using has_and_belongs_to_many :deals and has_and_belongs_to_many :stores (in the models)
My store custom form has the following:
f.inputs "Deals" do
f.has_many :deals do |deal|
deal.input :id, :as => :select, :include_blank => false
end
end
I don't know how to add deals to the store.
Any help?
Just checking, but do you have an
accepts_nested_attributes_for :deals #, :allow_destroy => true
declaration in your Store model, and an
accepts_nested_attributes_for :stores
declaration in your Deals model?
You may want to check these two pages:
http://apidock.com/rails/ActiveRecord/NestedAttributes/ClassMethods/accepts_nested_attributes_for
https://github.com/justinfrench/formtastic (search in the page for accepts_nested_attributes_for)