Checkbox Help

Hi guys,

I am need to help again. Sorry for the newbie query but would definitely
appreciate the help.

Here’s the q: I generate a list of items from the database and render
them out with a checkbox beside them. A user may click more than one
item and I would want to save all checked items into another table. I
have been able to give each checkbox a unique id . Would anyone be able
share some code example? What I’m not familiar with is how the values
are passed on by the form so that the def can handle it?

Thanks,

Bing

On 5/31/06, Bing [email protected] wrote:

are passed on by the form so that the def can handle it?

Thanks,

Bing

Depending on what your models look like you may be able to do this
fairly easy and have Rails do it automatically for you. But for a
basic version, try just doing a
<%= debug params %>
in your view, that’s where your data from the checkboxes appear. So
you should find the data in params[:formname][:checkboxid]

Hope that helps you get going in the right direction. :slight_smile: I have a very
similar thing I did myself just a few days ago, but I don’t have the
code for it here, I could pass it along later today if you want.

Mathias.

Try something like:

view:
<%= form_tag(:action => “item_check”) %>
… for each item …
<%= check_box (“to_check”, order.id, {}, “yes”, “no”) %>

<%= submit_tag %>
<%= end_form_tag %>

controller:
def item_check
if things_to_check = params[:to_check]
things_to_check.each do |item_id, act|
if act == “yes”

else

end
end
end
@items = Item.unchecked
end

Bing wrote:

are passed on by the form so that the def can handle it?

Thanks,

Bing


A | c/o Marie Eikrem, Fagerborggt 48A, NO-0360 OSLO
M | +47 411 44 384
W | http://www.foo.mu