HABTM relationships and retrieving multiple selects in contr


Hello all,

I have a product table and an option table that are connected to one
via a join table. These two tables both contain has_and_belong_to_many
relationships with each other.

I am trying to setup a page where I will create a product and add in its
options. I have already populated the options table with data to draw

so, to start, here is the method from my controller:
def new
@product = Product.new()
@opt = Option.find_all

and we go off to the “new” view, where I have this:

<select name=“product[options][]”, size=‘5’, multiple='multiple>
<%= options_from_collection_for_select(@opt, “id”, “name”, @
product.options) %>

other product creation code goes here…

This select statement does correctly draw the options that were found by
controller and put into @opt. before displaying this page.

This form submits to the create method of the controller, where I have
def create
@product = Product.new(params[:product])

Well, this create controller does not work. WebBrick reports “option
expected, got string”. I see that the option ID I select is being
passed in
as a parameter like “options”=>[“3”]. But obviously I cannot retrieve
option ids, create the options, and add them to the product, and save it
in such a simplistic manner. I’ve tried to figure out how to, but
I’ve read the Agile book, on page 356, but still can’t understand.

Can anyone provide some help?