Hi,
I'm having some trouble with my form. The thing is I'm using a loop to
generate check_box_tags and then when the user clicks submit I want to
be able to see what he checked. For each checked box I want to copy a
file to the corresponding directory.
Here I only checked "Geðsjúkraþjálfun" and then submitted.
The problem is in the controller. How can I loop through the cats hash
and check if the key is there? I now have something like this:
@flokkar.each do |flokkur|
if params[:cats][:flokkur] == 1
....do some stuff...
end
end
#(@flokkar is the array that I used to build the form.)
But i never execute the block inside the if condition check. I've also
tried params[:cats][flokkur] but nothing happens. How can I make ruby
check whether a key exists? Like if I had a string "foo" and a hash
"durr", how could I check if durr[:foo] exists without writing the whole
thing??
Hi,
I'm having some trouble with my form. The thing is I'm using a loop to
generate check_box_tags and then when the user clicks submit I want to
be able to see what he checked. For each checked box I want to copy a
file to the corresponding directory.
This is strange code. You're inside a form_for, so why are you using
check_box_tag rather than check_box ?
I read somewhere that I shouldn't do it like this, but I couldn't get
the info on checked/uncecked using check_box. Should I get rid of the
form_for and change the submit button to POST button_to? Why?
Thanks Saurabh Peshkar, ofc I should've done that, thanks!
This is strange code. You're inside a form_for, so why are you using
check_box_tag rather than check_box ?
I read somewhere that I shouldn't do it like this, but I couldn't get
the info on checked/uncecked using check_box. Should I get rid of the
form_for and change the submit button to POST button_to? Why?
No, you should fix the problem that's preventing you from using
check_box!
Thanks Saurabh Peshkar, ofc I should've done that, thanks!
This is strange code. You're inside a form_for, so why are you using
check_box_tag rather than check_box ?
I read somewhere that I shouldn't do it like this, but I couldn't get
the info on checked/uncecked using check_box. Should I get rid of the
form_for and change the submit button to POST button_to? Why?
No, you should fix the problem that's preventing you from using
check_box!
Thanks Saurabh Peshkar, ofc I should've done that, thanks!
Hi,
I've tried that, but I can't seem to have check_box write anything else
to params[:cats] other than nil. The only thing that happened was that
params[:cats] was an array the same length as the number of categories I
had but only contained nil-objects. Could you please show me how I
should generate the check_boxes inside the loop in my view?