Scaffold for boolean fields

1 view
Skip to first unread message

Bhaskar Jayakrishnan

unread,
Nov 6, 2007, 12:06:51 PM11/6/07
to Ruby on Rails: Talk
The default scaffold generator generates the following code for a
boolean field. This results in a past selection not being remembered
during edits.

<label for="model_active">Active</label>
<select id="model_active" name="model[active]">
<option value="false">False</option>
<option value="true">True</option>
</select>

I guess it should be:
<label for="model_active">Active</label>
<%= select("model", "active", [['True', true],['False', false]]) %>

This seems to be a rather basic operation for the scaffolding
generator to get wrong. Am I missing something?

- bhaskar

Bhaskar Jayakrishnan

unread,
Nov 6, 2007, 12:08:18 PM11/6/07
to Ruby on Rails: Talk
FYI: I am using Rails 1.2.5 (through InstantRails + update).


Brian Hogan

unread,
Nov 6, 2007, 12:19:12 PM11/6/07
to rubyonra...@googlegroups.com
First off:
 
Yes, it's basic. Because scaffolding is basic. It's also not meant for production use.
 
Second, people like the scaffolding because it builds forms for them :)
 
I just released a gem called scaffold_form_generator that does the form generation part of scaffolding (no controller, no model, just the form).  It's really meant for use in Rails 2.0 apps though since it uses RESTful routing and the new .html.erb syntax for forms.
 
You can learn more about that at http://scaffoldform.rubyforge.org

I prefer checkboxes for booleans... it's quicker and just makes more sense from a usability standpoint.
 
<%=check_box :model, :active %>
 
When you generate a form with scaffold_form_generator, that's what you get. :)
 
If you're looking for something more advanced than scaffolding, look at ActiveScaffold or Streamlined, two very nice projects that take scaffolding to a whole new level, one that could be used in production (though I still think you should code your own user interfaces, but I'm an HTML guy at heart.)
Reply all
Reply to author
Forward
0 new messages