O'Reilly logo

Learning Rails: Live Edition 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

Test Your Knowledge

Quiz

  1. How much type-checking does Rails do against the types you specified in your migrations?

  2. What happens when a validation error is reported?

  3. How do you customize the error notifications users see when their data doesn’t match up to your validator’s expectations?

  4. How do you test the detailed syntax of user-entered data to make sure it matches a particular pattern?

  5. If there’s more than one error reported by the validator methods, what does Rails do?

  6. How do you specify if something may be either valid or blank?

  7. How do you specify that a value has to be outside of a particular range?

  8. How can you specify that a validation applies only if another value in the form has a particular value?

Answers

  1. Rails does no type-checking by default. It just coerces the data that came in to the matching type, and if it doesn’t match, too bad. You have to provide explicit validation code for every field you create.

  2. Validation errors block the saving of records. The model sends the data back through the controller to the view, adding messages about what is wrong with the data so the view can display them.

  3. The :message named parameter lets you provide a specific notification. Rails will do some notifying by default, in basic cases, but you’re generally wise to add your own messages.

  4. The validates_format_of method lets you test against regular expressions, or you can write your own more complicated tests by extending validation through the validate method.

  5. Rails will report all of the messages from ...

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