Hello,

In your shop view change collection line to: <%=
f.collection_select(:city_id, City.find(:all), :id, :name,
options ={:prompt => "-Select a city"}, :class =>"") %>


On Mar 7, 9:13 am, Greg Ma <li...@ruby-forum.com> wrote:
> 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| %>
>   <p>
>     <%= collection_select(@shop,:city_id, City.find(:all), :id, :name,
> options ={:prompt => "-Select a city"}, :class =>"") %>
>   </p>
>   <p><%= f.submit "Submit" %></p>
> <% end %>
>
> Best,
> Greg
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to