Is it possible to write multiple checkbox values? When i click on
submit, the first value "accounting_services" is written to the
database, but all of the others are ignored.
I created a column in my registration database table with a title of
organizationservices, and type of string.
<td><%= f.check_box(:organizationservices, {:class =>
''check_box''},"accounting_services","")
%>Accounting/Auditing Services
</td>
<td><%= f.check_box(:organizationservices, {:class =>
''check_box''},"Actuarial_Services","")
%>Actuarial Services
</td>
<td><%= f.check_box(:organizationservices, {:class =>
''check_box''},"com_dev","")
%>Alternative/Comm. Dev. Investments
</td>
<td> <%= f.check_box(:organizationservices, {:class =>
''check_box''},"test 1","not test 1")
%>Test</td>
thank you,
Jason
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
There is a browser limitation on checkboxes. At least for some browsers, the checkbox value is only sent, if the checkbox is checked. for unchecked boxes nothing is returned. So you must check against params[:model_name][:checkbox_name].nil? or something like that. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason White wrote:> Is it possible to write multiple checkbox values? When i click on > submit, the first value "accounting_services" is written to the > database, but all of the others are ignored. > I created a column in my registration database table with a title of > organizationservices, and type of string. > > <td><%= f.check_box(:organizationservices, {:class => > ''check_box''},"accounting_services","") %>Accounting/Auditing Services > </td> > <td><%= f.check_box(:organizationservices, {:class => > ''check_box''},"Actuarial_Services","") %>Actuarial Services > </td> > <td><%= f.check_box(:organizationservices, {:class => > ''check_box''},"com_dev","") %>Alternative/Comm. Dev. Investments > </td> > <td> <%= f.check_box(:organizationservices, {:class => > ''check_box''},"test 1","not test 1") %>Test</td> > > thank you, > JasonHi there, so, the html you want to generate is; <input type="checkbox" name="organisation[organisationsservices][]" value="abc" /> this will create an array in the params :organisation => {:organisationservices => ["abc"]} with all the checked values being put in there. but, I dont think you can do this with the :form_for syntax. so, instead <td><%= check_box_tag("organisation[organisationservices][]", "accounting_services", @organisation.accounting_services.include?("accounting_services")) %>Accounting/Auditing Services </td> .... I suggest you wrap this into a helper if you need to use it a lot.. Matthew Rudy http://www.workingwithrails.com/person/12394-matthew-rudy-jacobs -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---