Hi,
I try to create a select menu with all the city available in my shop
form. I’ve been able to populate the select menu but the city_id isn’t
stored in the shop table. There must be an error in my view regarding
that i’m not sure to understand each parameters of the
collection_select.
Shop.rb
class Shop < ActiveRecord::Base
attr_accessible :total_visit, :friends_invited
has_and_belongs_to_many :products
has_and_belongs_to_many :owners
has_many :credits
has_many :visits
belongs_to :city
end
City.rb
class City < ActiveRecord::Base
attr_accessible :name, :continent
has_one :shop
end
Shop view
<% form_for @shop do |f| %>
<%= collection_select(@shop,:city_id, City.find(:all), :id, :name, options ={:prompt => "-Select a city"}, :class =>"") %>
<%= f.submit "Submit" %>
<% end %>Best,
Greg