What i want is to link my new policy when i create this one in his form with multiple countries.
You want to set a belongs_to :country
in your policy
model instead of has_many :countries
class Policy < ActiveRecord::Base
belongs_to :country
end
and has_many :policies
in your country
model
class Country < ActiveRecord::Base
has_many :orders
has_many :users
has_one :platform
has_many :policies
end
I want to use check boxes into this form to check what country i link (all countries stored in DB will be there).
For this,you can use collection_check_boxes.By setting like above(belongs_to :country
),you will get country_id
which you will be using with collection_check_boxes
to check/uncheck
the multiple countries.
Hope it helps!
Update
Might i have just wrong with the associations.In your case,it is a has_and_belongs_to_many.
class Policy < ActiveRecord::Base
has_and_belongs_to :countries
end
class Country < ActiveRecord::Base
has_many :orders
has_many :users
has_one :platform
has_and_belongs_to_many :policies
end