Skip to content

Instantly share code, notes, and snippets.

@tommeier
Forked from adamkleingit/user.rb
Created August 3, 2013 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommeier/6146493 to your computer and use it in GitHub Desktop.
Save tommeier/6146493 to your computer and use it in GitHub Desktop.
# Improve / Fix as many things in the code below
# Answers should be sent to hackademy@500tech.com
# Good luck
class User < ActiveRecord::Base
validates_presence_of :name, :email, :date_of_birth, :age_category
before_save do
age = (Time.now - date_of_birth).year
if age < 10 age_category = 'child'
elsif age < 18 age_category = 'teenager'
elsif age < 24 age_category = 'young'
elsif age < 54 age_category = 'adult'
else age_category = 'senior'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment