Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This model is user.rb
- class User < ActiveRecord::Base
- #Max & min lengths for all fields
- SCREEN_NAME_MIN_LENGTH = 4
- SCREEN_NAME_MAX_LENGTH = 20
- PASSWORD_MIN_LENGTH = 4
- PASSWORD_MAX_LENGTH = 40
- EMAIL_MAX_LENGTH = 50
- SCREEN_NAME_RANGE = SCREEN_NAME_MIN_LENGTH..SCREEN_NAME_MAX_LENGTH
- PASSWORD_RANGE = PASSWORD_MIN_LENGTH..PASSWORD_MAX_LENGTH
- validates_uniqueness_of :screen_name, :email
- validates_length_of :screen_name, :within => SCREEN_NAME_RANGE
- validates_length_of :password, :within => PASSWORD_RANGE
- validates_length_of :email, :maximum => EMAIL_MAX_LENGTH
- validates_format_of :screen_name,
- :with => /ˆ[A-Z0-9_]*$/i,
- :message => "must contain only letters, " + "numbers, and unscores"
- validates_format_of :email,
- :with => /ˆ[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i,
- :message => "must be a valid email address"
- end
- -----------------
- I cant user.save in the console as you can see below. I want to know where the mistake is.
- ----------------
- Shanes-iMac:~/rubydev/rails_space shanekillian$ script/console
- Loading development environment.
- >> user = User.new(:screen_name => "rails_rocks",
- ?> :email => "rails@example.com",
- ?> :password => "foobar")
- => #<User:0x356ed7c @new_record=true, @attributes={"screen_name"=>"rails_rocks", "password"=>"foobar", "email"=>"rails@example.com"}>
- >> user.save
- => false
- >> user.errors.full_messages
- => ["Screen name must contain only letters, numbers, and unscores", "Email must be a valid email address"]
- >>
Add Comment
Please, Sign In to add comment