Best practice for bound checkbox

490 views
Skip to first unread message

johan pretorius

unread,
Feb 3, 2009, 4:37:50 AM2/3/09
to Haml
There are various solutions to be found for Haml checkbox
implementations, such as:

a) = check_box_tag

b) = check_box()

c) %input{:type =>

Which is the better option to use with bound data?

I've tried them all, and although I managed to update the database,
the conversion from the data to a ticked or blank checkbox is not
working (eg. the tickbox is not representing the database value, which
is either 1 or 0).

Just to clarify, the checkboxes do not have to be created dynamically
from another table.

much appreciated,

Johan

Mislav Marohnić

unread,
Feb 3, 2009, 6:24:31 AM2/3/09
to ha...@googlegroups.com
Your question is not about Haml at all. It's more about your model and view helpers of the framework you use.

I guess you use Rails and ActiveRecord, so the solution would be:

- form_for @model do |f|
  = f.check_box(:foo)

Nothing fancy, just that.

johan pretorius

unread,
Feb 3, 2009, 6:39:01 AM2/3/09
to Haml
Mislav:
> Your question is not about Haml at all. It's more about your model and view
> helpers of the framework you use.

Sure, now that you mention it.

> I guess you use Rails and ActiveRecord, so the solution would be:

I'm actually using Merb & Datamapper, but you've pointed me in the
right direction.

> - form_for @model do |f|
> = f.check_box(:foo)
>
> Nothing fancy, just that.

I'll give it a try, thanks.
Reply all
Reply to author
Forward
0 new messages