Forum: Ruby on Rails HABTM relationships and retrieving multiple selects in contr

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
78e1e63b1c4789fb757317fe31d362b3?d=identicon&s=25 Shelby Westman (Guest)
on 2006-01-15 18:04
(Received via mailing list)
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 =
  @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])

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?

This topic is locked and can not be replied to.