Check_box not being checked

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

    <%= render(:partial => "list_item", :collection => @list.list_items) %>

And this is the partial _list_item.rhtml

  • <%= check_box 'list_item', 'done' %> <%= list_item.text %>
  • 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!

    BTW, same thing happens if I don’t use a partial.

    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 B.
    [email protected]

    Michael B. 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.


    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs