Hi, Does anyone have a link or information on how to handle lists of checkboxes in rails? I am working on a property site and each property has a list of features which are rendered as a list of checkboxes. I am trying to figure out how to handle which ones are checked and which not and persist them back to the database. Sorry for the noob question. Keith --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The check_box helper in your view and a call to update_attributes in your controller are all you need :) -- 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 -~----------~----~----~----~------~----~------~--~---
Cool, Didn''t know there was a checkbox helper. Thanks for the answer. Keith On 1/30/07, Mick Sharpe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > The check_box helper in your view and a call to update_attributes in > your controller are all you need :) > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Hi! On Jan 30, 2007, at 14:43, Mick Sharpe wrote:> > The check_box helper in your view and a call to update_attributes in > your controller are all you need :)Could you please give me the example of using the checkbox helper? I need to show a list of tags so that tags belonging to the page are checked. I''m bewildered with "method" parameter it should be a string and I don''t know how to write it if I want to call @page.includes?(topic). Your sincerely, Damian/Three-eyed Fish --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hi damian i recently did a similar thing, so here''s maybe what you are looking for - it may not be the best or most elegant way - i didn''t use checkbox helper, because i couldn''t get it going properly - i''m still a newbie, but this works in your view: <% for section in @sections%> <input type="checkbox" id= "<%section.id%>" name="section_ids[]" value="<%=section.id%>" <%if @content.sections.include? section %> checked="checked" <%end%>><%=section.name%> <% end%> in controller (new or create): @content.sections= Section.find(@params[:section_ids]) if @params[:section_ids] hope this helps george --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I just tend to use: <%= check_box("product", "is_active") %> where "product" is an AR object stored in @product, and "is_active" is a column name of type boolean (if the method is a string, it is taken to be an AR column name). Further information can be found in the Rails wiki: http://wiki.rubyonrails.org/rails/pages/HowToUseCheckBoxes -- 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 -~----------~----~----~----~------~----~------~--~---
On Tuesday 30 January 2007 12:24, Keith Davey wrote:> Does anyone have a link or information on how to handle lists of > checkboxes in rails?Try this plugin http://www.agilewebdevelopment.com/plugins/multiple_select_helper HTH, Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Michael, Just tried it out and it does exactly what I was looking for and in good rails style it took about 5 minutes as well. Keith On 1/31/07, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> > > On Tuesday 30 January 2007 12:24, Keith Davey wrote: > > > Does anyone have a link or information on how to handle lists of > > checkboxes in rails? > > Try this plugin > > http://www.agilewebdevelopment.com/plugins/multiple_select_helper > > HTH, > Michael > > -- > Michael Schuerig > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org > http://www.schuerig.de/michael/ > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 31, 2007, at 16:30, mr_robot wrote:> > hi damian > i recently did a similar thing, so here''s maybe what you are looking > for - it may not be the best or most elegant way - i didn''t use > checkbox helper, because i couldn''t get it going properly - i''m still > a newbie, but this works > > in your view: > <% for section in @sections%> > > <input type="checkbox" id= "<%section.id%>" name="section_ids[]" > value="<%=section.id%>" > <%if @content.sections.include? section %> > checked="checked" > <%end%> >> > > <%=section.name%> > > <% end%> > > in controller (new or create): > @content.sections= Section.find(@params[:section_ids]) if > @params[:section_ids] > > hope this helps > > georgeThank you very much! This is an approach I''m using now, I just wanted to see whether I can write less code. I''m thinking of writing my own helper for it, but as I''m a newbie, I should find out how to do it. Yours sincerely, Damian/Three-eyed Fish --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---