On 10/24/06, Chris G. [email protected] wrote:
In the controller I’ve added this line
“Selected may also be an array of values to be selected when using a
multiple select.”
Well I didn’t read that in the documentation (probably glanced over)
but I
assumed that was a possibility.
So it looks like you need to pass it an array of values (i.e. strings).
I haven’t tried this, but I’m guessing it’s failing because you’re
creating an array of entire Canindustry objects and passing that. You
need to get just the names.
Actually as it turns out I needed the id - so this returned the list -
@canindustry_options = Canindustry.find(:all,:conditions =>
[“candidate_id =
?”, @candidate_id]).map {|c| c.category_id}
Just changed name to category_id in controller code.
See if this works:
Why are you building your options list from a query on Category, but
building your selected options from a query on Canindustry? Your
selected options should (obviously) be a subset of all options. How are
you storing your selected options? I don’t know your models, of course,
but I think your currently selected categories aren’t actually correctly
represented by a list of Canindustry objects …
Hmmm…not entirely sure what you mean here. However maybe I can
explain.
Category is model that contains a list of categories. It’s not a table
that
is altered in any way by the user. It’s use within the application is
so
users may select multiple categories from it. I store user input in
tables
as category_id. The table is rails compliant - meaning their are 2
fields,
id | name. When the user needs to see what they selected I can show
them
with - <%= mychoice.category.name %>
Canindustry - is a model / table is where the user selections are
stored.
So the table is something like | id | category_id |.
So I think , perhaps the confusion of what my intentions are is that I
wish
to let the user choose more, less or the same on update / edit.
For example -
User Joe
Canindustry:
(first time creating their selections)
| id | candidate_id | category_id |
1 5 2
2 5 6
3 5 8
(second time: updating their selections)
1 5 2
2 5 5
So on the update, Joe deleted record with id 3
and changed record with id 2 to option 6
This explain it better ?
Stuart