Hi
I''m a Rails newbie, trying to implement a simple many-to-many
relationship editor. I''m using a form with collection_select but I
can''t successfully get the menu selection result out of the form.
I''ve got two tables (locations and people) and a joining table
(locations_people). My Location model has_and_belongs_to_many people
and vice versa.
In my person_controller I''ve got a new method:
def new
locations = []
@all_locations = Location.find(:all)
@person = Person.new
@new_location = Location.find(1)
end
and a create method:
def create
@person = Person.new(@params[:person])
@person.locations<< Location.find(@params[:out_location])
if @person.save
flash[''notice''] = ''Person was successfully
created.''
redirect_to :action => ''edit'', :id => @person
else
render_action ''new''
end
end
and in my form I''ve got:
<label for="location_start">Start
location</label><br/>
<% @out_location = @new_location %>
<%= collection_select(:out_location, :id,
@all_locations, :id, :name) %>
I''ve tried several different things to extract the selected
location_id but can''t figure it out. Can anyone help?
Thanks in advance,
Dion
http://dionandsarah.blogspot.com