Overriding default rails forms

0 views
Skip to first unread message

Eric Richmond

unread,
May 13, 2008, 6:03:09 PM5/13/08
to Boston Ruby Group
Hey all,

Has anyone had any experience with writing their own forms in rails,
effectively overriding all of the 'built-in' stuff that ActionView
likes to do?

Is it worth trying to write everything from scratch so it looks the
way you want, or does it just make more sense to 'embrace' the
template that rails provides and work within that framework?

Any input would be greatly appreciated.

-Eric

Doug Pfeffer

unread,
May 13, 2008, 6:04:21 PM5/13/08
to boston-r...@googlegroups.com
Eric,
What kind of customization do you mean? Adding labels? Changing the
error field markup?

Doug

Eric Richmond

unread,
May 13, 2008, 6:29:04 PM5/13/08
to Boston Ruby Group
More along the lines of changing the error field markup. It's a pain
writing custom CSS to pretty up a form, just to have the error field
stuff destroy it. :)

But even on a broader level, are people just using the baked in form
code in general? Or do most people override that part of rails?

-Eric

On May 13, 6:04 pm, "Doug Pfeffer" <doug.pfef...@gmail.com> wrote:
> Eric,
> What kind of customization do you mean? Adding labels? Changing the
> error field markup?
>
> Doug
>

Andrew Kuklewicz

unread,
May 13, 2008, 8:58:08 PM5/13/08
to boston-r...@googlegroups.com
$.02
I use an extensively customized form builder with a set of css definitions to let me do different layouts, and automatically 'star' required fields, automatically show labels, and additional help text when necessary.

-Andrew
Andrew Kuklewicz


Doug Pfeffer

unread,
May 13, 2008, 9:12:16 PM5/13/08
to boston-r...@googlegroups.com
You can also tweak the error markup with
ActionView::Base.field_error_proc, in your environment file.
This example output the error message(s): http://pastie.caboo.se/196532

Doug


On Tue, May 13, 2008 at 8:58 PM, Andrew Kuklewicz
<and...@beginsinwonder.com> wrote:
>
> $.02I use an extensively customized form builder with a set of css

Tom Harrison

unread,
May 13, 2008, 9:30:17 PM5/13/08
to boston-r...@googlegroups.com
I have an app that uses lots of forms.  I am of simple brain, and so just follow Rails' conventions.  Smarter and more clever people would shun my simpleton ways.

I started with a recipe in the newest AdvancedRailsRecipes book from PragProg (very good, IMHO) that overrides form_for and helpers so that form helpers:
* accepts a label parameter that generates a label
* accepts a field help message
* accepts a "required" parameter for styling the field and for validation
* works with plugins, notably calendar_date_select
* works with child model forms (e.g. a project has many tasks)
* handles standard rails validations, even in child forms (which normal Rails doesn't, I think)
* works with other standard form_for helper parameters specific to the type
* generates consistent HTML that I style with a reasonable (if somewhat dense and old-school/non-ajaxy) CSS class

such that I can write form (new and edit) forms like
  <ol>
    <%= f.select :kind, Project::PROJECT_KIND, :required => true, :prompt => "Which kind is it?", :size => 30, :help => "What kind of project is this? Big, little, or just a thing to be done?" %>
    <%= f.select :visibility, Project::PROJECT_VISIBILITY, :required => true, :prompt => "Who can see it?", :help => "Who can see this?" %>
    <%= f.text_field :name, :required => true, :help => "A brief, descriptive title for the project to help people understand what and why more clearly." %>
    <%= f.text_area :objective, :required => true, :cols => 22, :rows => 4, :help => "How will you know when this project is done?" %>
    <%= f.text_area :instructions, :cols => 22, :rows => 4, :label => "Details", :help => "Other information necessary to understand the task" %>
    <%= f.calendar_date_select :due_date, :class => "date", :help => "If you have a goal date for completion of the project, you can set it here.  Once the project is up and running this is an important thing to keep track of!" %>
    <%= f.select :status, Project::PROJECT_STATUS, :prompt => "Select a status", :help => "What's the current status of the task?" %>
 </ol>

What I still feel is needed:
* have radio buttons work (bug fixed in Rails 2.1 does not generate unique ids), may also affect checkboxes
* have the scaffold generators produce the format out of the box (maybe..., or make a new generator/converter)
* have the partial that results in the add/edit forms also produce the "show" view
* come up with better html and CSS that produces nicer looking help (I am a Luddite with HTML/CSS/JS)

Feel free to look at http://doAGreenThing.com/ which is a work in progress...

Please let me know if you're interested in the code.

Tom Harrison

On Tue, May 13, 2008 at 8:58 PM, Andrew Kuklewicz <and...@beginsinwonder.com> wrote:

eric.richmond

unread,
May 14, 2008, 12:02:11 PM5/14/08
to boston-r...@googlegroups.com
Wow!

Thanks for all the great responses guys.

I think modifying that recipe seems like the way I'll go.  I'll let you guys know how it turned out :)

-Eric
Reply all
Reply to author
Forward
0 new messages