Hi !
2006/1/27, Elan <elan@nospam.bardoworks.org>:> <%= collection_select(:event, :location, @locations, :id, :name)
%>
> ..
>
> The problem is that in the controller, when I create a new event, it
> says it expects a Location and not a string: "Location expected, got
> String" in the "@event = Event.new(params[:event])" line.
>
> I''m a bit confused...shouldn''t Rails have enough
information to turn the
> location ID into a full location, and actually, shouldn''t the ID
be
> enough in this case?
Change your collection select line to:
<%= collection_select(:event, :location_id, @locations, :id, :name) %>
Notice the field name ? You were assigning a String to a Location
instance. Now, you will be assigning to an attribute that expects a
Fixnum, and Rails will attempt to convert the Fixnum into a String, so
everything will be right.
Hope that helps !
--
Fran?ois Beausoleil
http://blog.teksol.info/