I''m new to RoR and I''m having a little problem that I can''t solve. My model is simple. I have Lists and ListItems. I have a view that loops through all the list items, and I put the HTML for the each list item row in a partial called _list_item.rhtml. This is the view, called show.rhtml <ul> <%= render(:partial => "list_item", :collection => @list.list_items) %> </ul> And this is the partial _list_item.rhtml <li> <%= check_box ''list_item'', ''done'' %> <%= list_item.text %> </li> As you can see, my list_item has two fields: done and text. The problem is that even though the field done is an integer "1" I can''t get the checkbox to get checked!!! The rest works as expected. Any idea? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
BTW, same thing happens if I don''t use a partial. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try putting this at the top of your partial: <% @list_item = list_item %> The magic form helper methods rely on instance variables to set the value. Alternatively, you could do this: <%= check_box_tag "list_item[done]", list_item.done %> Michael Bleigh michael-+08J6pdAJjhWk0Htik3J/w@public.gmane.org On Dec 15, 2007, at 4:28 PM, Marcelo Ruiz wrote:> > I''m new to RoR and I''m having a little problem that I can''t solve. > > My model is simple. I have Lists and ListItems. > > I have a view that loops through all the list items, and I put the > HTML for the each list item row in a partial called _list_item.rhtml. > > This is the view, called show.rhtml > > <ul> > <%= render(:partial => "list_item", :collection => @list.list_items) > %> > </ul> > > And this is the partial _list_item.rhtml > > <li> > <%= check_box ''list_item'', ''done'' %> > <%= list_item.text %> > </li> > > As you can see, my list_item has two fields: done and text. > > The problem is that even though the field done is an integer "1" I > can''t get the checkbox to get checked!!! > > The rest works as expected. > > Any idea? Thanks! > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Bleigh wrote:> Try putting this at the top of your partial: > > <% @list_item = list_item %>I was struggling with this myself last night. Had done this before but forgot about the instance var. Thanx -- 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 -~----------~----~----~----~------~----~------~--~---