Tabular FormBuilder for easily creating forms in Rails
Thursday, July 13, 2006 at 1:11PM * [Prettier Accessible Forms](http://alistapart.com/articles/prettyaccessibleforms)
* [Awesome Forms](http://paularmstrongdesigns.com/examples/css/awesome-form.html)
but they have their quirks and disadvantages too. So I decided to be irritatingly pragmatic for now and use tables. I know, it's not *right*, but it's good enough, OK?
So, I created a form builder to produce them. Actually I first created it back in May, but I've finally gotten around to using it in anger, so it's been tidied up a little, and a few features added. You can grab a copy from my plugin repository with the following magick juju:
script/plugin install http://svn.rubaidh.com/plugins/trunk/form_builders
Add `-x` to make it an `svn:externals` and keep up to date with the latest version.
To make it work, you'd do something along the lines of:
{:multipart => true}) do |f| %>
true %>
true %>
'Longer description' %>
Notice how easy it was to create a form there, that will be styled consistently with all your other forms in your application? Nice. :-) I've added a couple of extra options. If you pass `:required => true` into a field, it'll stick a '*' next to the field (and in true convention-over-configuration form, that's hard-coded, so tough :-P ). By default it will create a label by humanising the field name, but you can always pass in something more friendly with `:label => 'Friendly field label'`.
That's about it, really. Dead simple. As usual, I'm open to feedback on improving it. And patches. Especially patches, in fact. :-)
Geekery,
Ruby and Rails,
Work
Reader Comments (10)
I made a little change to add some date convenience methods:
module Rubaidh
module TabularForm
class TabularFormBuilder < ActionView::Helpers::FormBuilder
(field_helpers - %w(check_box radio_button) %w(date_select datetime_select)).each do |selector|
...
Pretty dirty, but quite handy. There's probably a better way to figure out which methods to add here. :)
Thanks for your plugin!
On the latest Rails prerelease, this plugin will fail to load in development mode after the first request (seem like something to do with reloading of plugins). They aren't supposed to reload at all anymore. Any ideas? Cheers!
I have the same problem, not loading after the first request. I am looking into it right now.
I worked around the problem by directly including the plugin in my application helper for now.
Joshua, the problem is that the init.rb file of the plugin extends ApplicationHelper, instead it should extend ActionView::Base. Just a simple change to get this working again, should be backwards compatible aswell.
I tried that workaround by Tarmo but the plugin is still broken.
Tarmo: Thanks for pointing out the fix. I've now incorporated it in svn.
Y'all might want to look at http://svn.rubaidh.com/plugins/trunk/yet_another_form_builder which, thanks to a good friend & CSS guru, now appears to lay out forms nicely with CSS. Score! At some point, I'll document it and release it properly...
Hm looks nice. Is this the best there is for rails 2.0? I'm new ... how do I use it,
I tried both and both gave a 500, it says tabular_form_for not found
I like aurita-gui better. It's a real form generator, not just some views helper. Just look at the examples, i love it.
http://aggrgator.com/doc/aurita-gui
sudo gem install aurita-gui
It's the best form builder implementation for ruby i ran across.
There's no view helper for aurita-gui (it's plain ruby, no rails plugin), but this should be trivial.
The plugins can now be found here
git://github.com/rubaidh/form_builders.git
and here
http://github.com/rubaidh/form_builders
with info here
http://rubaidh.com/portfolio/open-source/form-builder/