We are working on a database and need the capabilities to have a drop
down field (list) that can handle multiple selections. For example, if
it say to me please enter your favorite cars from this list and wanted
to use a list instead of a checkbox, it is possible. However, we
cannot figure out how to store the data in the database, retrieve the
values from the database and the type of field to choose. We know in
PHP this is called “form array data” but the code for ruby seems
limited. Anyone know where we can find code for ruby on rails to do
this? Thank you in advance!
We are working on a database and need the
capabilities to have a drop down field (list) that
can handle multiple selections.
WRT the type of field to use to collect the selections, see the
documentation for select_tag at http://api.rubyonrails.org/ . Can’t
figure
out what it is you’re stuck on wrt to the other items.
This is the html code and the backend is a ruby on rails server
connecting to mysql. We need to use a selection box to give a list of
options that you can choose multiple entries and submit the form. It
should store the multientry field so it can be retrieved and show
selected when editing the data again. Sorry if this is confusing but I
am not sure hwo to explain it.
thank you…will try this tonight when I get home and will update you
after. Thanks again for the quick replies.
just curious, should the mysql field be char or int?
Once we figure this out the 2nd part will be to perform a join from the
information stored in this field back to our keyword list table and
return the text values. We have a table with a coupld hundred keyword
values that are used throughout the system so it will need to join back
to show in the list. It always the stupid little things like this that
get us stuck.
Rails expects things to be structured a certain way in order to perform
its magic (convention over configuration).
If the foreign key is named after the table it refers to with a
trailing “_id”, then rails can do all the joining for you as described
by your models. Specifics are a little tricky without the schema but
check out
So we go it to store the values or so we think…this is what we see in
the varchar field…is that the right data type for the field? Should
we do int? Those numbers correspond to our keyword table and the key
from that table.
however, we are not sure how to get it to show the values that were
selected when going into the edit form. I have to say we have written
so many things in ruby and this has been by far the most frustrating
(due to lack of doc).
it not difficult…the code just does not seem to work as it should.
Your code might work if we were using a regular list. However, our
values come from another table that hold our keywords. I wish I could
just show you and then it would make sense.
Unfortunately the documentation for rails is poor, which does not help
newbies like myself, or even experienced developers like DHH (see http://coderpath.libsyn.com/index.php?post_id=160139). We need
documentation like Django’s.
it not difficult…the code just does not seem to work as it should.
Your code might work if we were using a regular list. However, our
values come from another table that hold our keywords. I wish I could
just show you and then it would make sense.
Ahh - now I see the reasons - the arrays do not line up like I thought.
Are they related via foreign keys? If so you will be able to build a
single array that sticks it all together, then use a variation of the
code above.
It is based on a foreign key. The table field myrep contains the
foreign key relation from the keyword table. The numbers 1830, 1832
and 1833 (seen above) are the id of the entries in the keyword table.
We normally write sql statements to join them together (for single
instance drop down boxes). However, in this case we cannot figure out
how to pull apart the string array stored in the varchar field. If you
could pull it apart I am pretty sure we could do some sql stuff to join
the names in the list. Do you know how to parse the string array
stored in the varchar field?
It is so strange when it comes to ruby 99% of the things are so easy
but this one has us in a tail spin. I have been writing in ruby on
rails for about a year now and the lack of doc has made it a bit
difficult but not hard…but it is getting there between this google
site the api site.