O'Reilly logo

Learning Rails by Edd Dumbill, Simon St. Laurent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Standardizing Your Look with Form Builders

While Rails scaffolding is a convenient way to get started, you may have noticed that it’s pretty repetitive and not especially attractive. Some of this can be fixed with judicious use of CSS, but Rails supports more permanent fixes through the use of form builders. Creating form builders is an opportunity to define how your data will be presented to users and how they’ll interact with that data. Form builders also let you create abstractions that keep programmers out of the visual details of your application while still giving them full access to views.

The basic concepts behind form builders are simple, though you can use them to create complex and intricate components. You can use form builders in multiple ways, starting from simple wrapping of your own special types and developing through more complex ways to change the ways forms are written.

Note

You can also combine form builders with Ruby metaprogramming to create your own terse yet descriptive syntaxes for creating forms, but metaprogramming is way beyond the scope of this book. If you encounter an application with view code that looks nothing like you expected, though, that may be what’s going on.

Supporting Your Own Field Types

Chapter 6 showed how Rails supported a variety of data types by default, including a more complicated (if not very user-friendly) set of controls for entering dates. While the built-in set of widgets is helpful, you’re definitely not limited to it. You can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required