On Mon, 2009-09-14 at 01:28 -0700, Frederick Cheung wrote:
> 
> 
> On Sep 14, 6:11 am, Craig White <[email protected]> wrote:
> > I'm using check_box but I'm not married to it, probably because I don't
> > understand it. Basically, I am presenting a list of upcoming payments
> > and I want to select which items are to be paid...
> >
> > <% form_for :supptrans, @supptrans,
> >  :url => { :action => "accept_checks" } do |form| %>
> >  <% odd_or_even = 0
> >   for check_due in @supptrans
> >   odd_or_even = 1 - odd_or_even
> >  %>
> 
> Take a look at the cycle helper as an alternative to this
----
I will but not for this application because there is so little of this.
But thanks for mentioning it because I know I am using an antiquated
method I found in one of the original AWDWR
----
> 
> 
> > and it returns a value of '0' because it was unchecked.
> >
> > I was hoping that it would return each line item that was checked or all
> > of the line items and I could loop through them and discard the
> > unchecked items but I only get the first value, nothing else.
> >
> 
> You should use check_box_tag rather than check_box for this. Then it's
> all about giving your check boxes the right names and the right
> values: rather than the value submitted being 1 you want the value
> submitted to be the id of the item in question. If you give the check
> boxes the same name and that name ends in [] then rails will collect
> the submitted values into an array for you
> 
> I wrote a bit more about parameter names at
> http://www.spacevatican.org/2008/7/18/parametrised-to-the-max
----
thanks, the key was the [] and I had to re-read your message a second
time before the light bulb turned on.

for completeness (if anyone wants what the solution was), the line
became

      <td><%= check_box_tag "supptrans[]", check_due.id, false %></td>

Thanks Fred,

Craig


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


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

Reply via email to