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
(Continue reading)

Naija Guy | 23 Jul 15:43

Re: cannot figure out how to handle multi checkbox


I had seen that, but it's not clear to me (and some of the people who 
commented on there agree with me).  As I said, my checkboxes are not 
tied to a model.

Dejan Dimic wrote:
> take a look at http://railscasts.com/episodes/17
> 
> 
> On Jul 23, 8:13�am, Naija Guy <rails-mailing-l...@...>

--

-- 
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 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
-~----------~----~----~----~------~----~------~--~---

Dejan Dimic | 23 Jul 17:13

Re: cannot figure out how to handle multi checkbox


As I find somewhere on the net:

View (as many times as needed):

        <input id="item_selected_keywords" name="selected_keywords[]"
        type="checkbox" value="exterior" />

Controller:

        selected_keywords = params[:selected_keywords]
        @item.keywords = selected_keywords.join(" ")

On Jul 23, 3:43 pm, Naija Guy <rails-mailing-l...@...>
wrote:
> I had seen that, but it's not clear to me (and some of the people who
> commented on there agree with me).  As I said, my checkboxes are not
> tied to a model.
>
> Dejan Dimic wrote:
> > take a look athttp://railscasts.com/episodes/17
>
> > On Jul 23, 8:13�am, Naija Guy <rails-mailing-l...@...>
>
> --
> 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
(Continue reading)

Naija Guy | 23 Jul 18:15

Re: cannot figure out how to handle multi checkbox


Actually, I wanted the results in a collection or array to iterate over 
in my next view, so this is what worked for that last line in the 
controller:

@item.keywords = selected_keywords

I was just trying really hard to use the Rails view helpers for a 
checkbox, but if I have to use straight HTML, then by no means am I 
opposed.  It just seems like one of those Rails helpers should work for 
me, but I figure it's because I don't understand them and when I look at 
the examples in the API docs, they don't seem to be applicable for my 
case (or I just don't get them).

Thanks...

Dejan Dimic wrote:
> As I find somewhere on the net:
> 
> View (as many times as needed):
> 
>         <input id="item_selected_keywords" name="selected_keywords[]"
>         type="checkbox" value="exterior" />
> 
> 
> Controller:
> 
>         selected_keywords = params[:selected_keywords]
>         @item.keywords = selected_keywords.join(" ")
> 
(Continue reading)


Gmane