Homework for 11A

Review

Topics Covered: Validations; custom validations


Exercises

E1: Validations Review

  1. Where do you write validations and why? Are there any validations that go in the controller?
  2. Why does the code below respond false on user.save?. When does a user.valid? return true?
    >> user = User.new(:name => "", :email => "mhartl@example.com") 
    >> user.valid?
    => false
    >> user.save
    => false
  3. What's one line of code to check if a User attribute has any errors? Hint: We did this in the console.
  4. Is it possible to validate relations? Think of validations for the relations in the Twitter app. Hint: Google for Rails relations validations.

E2: I Need Validation

Let's add some validations to MeowBook because, well, some of us are just insecure sometimes.


Projects

The Real Deal

By the end of the day you'll have to present your project specifications to Micah! This is the time to really crank out some good thinking about how you want your project to turn out, so put in the work now to save lots of time in the future.