In rails 4 application With has_many :through relations
city.rb
has_many :business_type_cities
has_many :business_types, :through => :business_type_cities
business_type.rb
has_many :business_type_cities
has_many :cities, :through => :business_type_cities
businesstypecity.rb
belongs_to :buness_types
belongs_to :cities
business_types_controller.rb
def create
if business_type.save
BusinessTypeCity.create :business_type_id => business_type.id, :city_id => params[:cities]
flash[:notice] = 'Business Type Created Successfully!'
redirect_to admin_business_types_path
else
flash[:error] = business_type.errors.full_messages.join(', ')
end
end
but here city_id is array and I want to store business_type_id and city_id in one row, other city_id will store in different row with same business_type_id.
Response I get is following:
"business_type"=>{"name"=>"test", "review_type"=>"review_with_rating"}, "cities"=>["293", "1091", "1200"], "commit"=>"Create Business Type"
Thanks