I’ve tried pulling this together from examples in the book, searching
the web and this list, but so far I’ve not been able to get it working
just right.
My table is a categories table with id and category fields.
My form has the following:
I used [[cat.category, cat.category] as I am not interested in the id
and want both values to be equal to the category itself.
This form is a Donation form. One of the fields in the donation record
is a category. The database does not relate these two tables. What I
want to do is simply populate the dropdown category box from the
categories table and allow a category to be selected and that category
be populated to the donation record.
In other words:
- Pull all categories into the form from the categories table into a
dropdown box on adding the record - Upon editing the record, again pull the categories as in step one,
but this time cause the category selected when the record was added to
be selected in the dropdown box, otherwise upon update the wrong
category would be updated to the record.
The dropdown box is populated with the categories; however, when the
record is added to the database, the category field is not populated.
The log file shows the following:
e[4;35;1mCategory Load (0.078000)e[0m e[0mSELECT * FROM categories
ORDER BY category e[0m
So far so good.
And then on adding the record:
Parameters: {“commit”=>“Create”, “category”=>{“category”=>“Furniture -
Kitchen”}, “action”=>“create”,
e[4;35;1mSQL (0.062000)e[0m e[0mINSERT INTO donations
(best_contact_time
, city
, created_on
,
item_desc
, category
, …
The category of “Furniture - Kitchen” is probably the eighth in the list
and is in fact the one chosen.
Two things then:
-
Why isn’t this being updated into the database record (the field in
the donation record is named category) -
Will the current code be sufficent to cause the category in the
record to be selected upon editing of the record? Since the code in the
form populates the dropdown box, might I need to then after that
immediately cause the category from the record to be the selected value
with following additonal code?
I suspect that there is no actual “selection” happening and if there
were, the donation’s record field would be populated and that would also
solve the issue when updating as well, and yet the create statement in
the log file appears to be showing a value!
Thanks for any help on this. I’ve found the dropdown boxes to be
particularly troubling.