Check_box form helper questions/issues

I’m using Rails 1.1.x and it looks like the check_box form helper
expects me to provide and object and method so it can determine if the
checkbox should be checked or not. I’m having a couple of issues with
this.

note: I’m using UserEngine and adding a HABTM so that:

class User < ActiveRecord::Base
has_and_belongs_to_many :foos
end

class foo < ActiveRecord::Base
has_and_belongs_to_many :users

def attached?(user = session[:user])
return false unless users.find(user.id)
end
end

and in my .rhtml I have this:

<% for foo in @foos %>
<%= check_box foo, attached? %>
<% end %>

Even if I verify in the console that the current user is in foo’s user
array, I never get a checked value in my form.

  1. I can’t see to tell if foo.attached? is being called
  2. If I try and explicitly call foo.attached? in the .rhtml, I get an
    exception that in the call of attached?, user is nil. So it’s almost
    like session[:user] isn’t in scope during the call. That seems odd,
    too.
  3. Should I dump the helper and write my own .rhtml to render the form?
    If so, I run into (2) again because user is nil

Thoughts?
–dwf

if you just want to render a checkbox without an object, you could use
check_box_tag instead i believe.

http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000500

DWFrank wrote:

I’m using Rails 1.1.x and it looks like the check_box form helper
expects me to provide and object and method so it can determine if the
checkbox should be checked or not.

Josh K. wrote:

if you just want to render a checkbox without an object, you could use
check_box_tag instead i believe.

Thanks! The *_tag helpers work more like I expect, allowing full
expressions for the value/state.

–dwf