Mystified by forms and models

Sean Colquhoun wrote:

Okay. Either I'm missing something WAY basic or Rails and its API are
lying to me (experience tells me it's the former). Here is the basic
setup for a check_box tag in the API:

<%= check_box('object', 'method') %>

So here's what I type in.

<%= check_box('todoitems', 'done') %>

"todoitems" is my table, and "done" is one column in that table. Hence,
it is todoitem's method. But Rails keeps giving me this error:

undefined method `done' for #<Array:0x416fb18>

Now, I think that this has something to do with me making these
checkboxes in a loop. But I don't understand what I'm doing
wrong. Anybody care to enlighten me?

You've set @todoitems to either a has_many association or the result
of a find(:all,..,) -- a collection or an array of ActiveRecord model
objects. However Rails' AR form helpers expect their first argument to be
the name of an instance variable that holds a single ActiveRecord object.

So you want

    <% for @todoitem in @todoitems %>
      <%= check_box :todoitem, :done %>
    <% end %>