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's the form:
<%form_for :cats, :url => {:action => :save_mt} do%>
<%[email protected] do |flokkur|%>
<p>
<%= check_box_tag("cats[#{flokkur}]",1,false) %>
<%= flokkur %>
</p>
<%end%>
<%= submit_tag "Vista mælitæki", :class => 'submit'%>
<%end%>
Development.log shows these parameters have been passed:
Parameters: {"commit"=>"Vista mælitæki",
"authenticity_token"=>"B2u5ULNr7IJ/ta0+hiAMBjmjEtTtc/yMAQQvSxFn2d0=",
"cats"=>{"Geðsjúkraþjálfun"=>"1"}}
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??
BR,
Sindri
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.