Dejan Dimic | 23 Jul 08:20

Re: cannot figure out how to handle multi checkbox


take a look at http://railscasts.com/episodes/17

On Jul 23, 8:13 am, Naija Guy <rails-mailing-l...@...>
wrote:
> I have a checkbox that is not tied to a model.  Basically, here's what
> the beginning looks like in the view:
>
> <% for entrant in @entrants %>
>           <tr class="<%= cycle("even", "odd") %>" >
>             <td><%= check_box ("to_check", entrant.firstname, {},
> checked = "false") %></td>
>
> This submits to a controller action that has only the following line:
>
> @firstnames = params[:to_check]
>
> I'm trying to display the results on the next page:
>
>       <% for firstname in @firstnames  %>
>             <br />
>             <%=h firstname %>
>
>         <% end %>
>
> This seems really simple.  Right now it's displaying every firstname in
> the array whether it was checked or not.  I tried another way and it
> only returned the first element in the array (so the names overwrote
> each other).  How do I check in the controller action method to see
> which ones were checked?  I'm coming from a Java web background and am a
> beginner with Ruby on Rails and have been Googling extensively, but I'm
> not understanding the examples, and the two recent Rails 2 books I have
> (one in PDF form) are confusing me as well.
>
> I tried to figure out how to use check_box_tag as well in case that's
> more appropriate in this case, but I'm just not sure what to do.  How
> should I change the form code and the controller so that I can retrieve
> only the firstnames that were checked? The HTML checkboxes should only
> send up the firstnames when checked.
>
> Thanks so much!
> --
> Posted viahttp://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 rubyonrails-talk@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Gmane