Skip to Content
Learning Rails
book

Learning Rails

by Simon St. Laurent, Edd Dumbill
November 2008
Beginner
448 pages
12h 25m
English
O'Reilly Media, Inc.
Content preview from Learning Rails

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Rails 5

Learning Rails 5

J. Mark Locklear, Eric J Gruber, Barnabas Bulpett

Publisher Resources

ISBN: 9780596154943Errata