Chapter 6. Presenting Models with Forms

The previous chapter showed how Rails makes it easy to create simple applications using scaffolding, but a key aspect of Rails scaffolding is that it isn’t meant to be permanent. This doesn’t necessarily mean that you’ll tear it down completely and start over, but it usually means that you’ll at least make substantial improvements to make it more attractive. This is especially important where information is coming in from users. While Rails scaffolding provides basic functionality, you’re very likely going to want to improve on the forms it creates.

More Than a Name on a Form

To demonstrate a reasonably complete set of HTML form features, the application needs to support more than one data field and needs to support fields in a variety of different types. Rails, because it works with a wide variety of databases, supports a narrower set of types than each of those databases. The types of fields that Rails supports through ActiveRecord include:

:string
:text
:integer
:float
:decimal
:datetime
:timestamp
:time
:date
:binary
:boolean

The :string type is generally limited to 255 characters, whereas :text can hold longer data. The :integer, :float, and :decimal types all hold numbers, although integers may not have a fractional part to the right of the decimal point. The :datetime, :timestamp, :time, and :date types hold the classically complicated combination values used to represent dates and times. The :binary type can hold unstructured binary data, ...

Get Learning Rails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.