Rymo4
Rymo4

Reputation: 471

Case Insensitivy in Rails

I have a users sign up form, but when the users sign back in they are required to type their email address with the same cases as they signed up with. I have measures to prevent this, but for some strange reason they are not working.

In the users model:

validates :email, :presence => true,
                  :format   => { :with => email_regex },
                  :uniqueness => { :case_sensitive => false }

email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

This was not working... im not sure why. but then I added another method to see what it did:

before_save :downcase_fields
def downcase_fields
 self.email.downcase 
end

and down cased the fields when users type them in with this in my sessions controller:

def create
    user = User.authenticate(params[:session][:email].downcase,
                          params[:session][:password])
    #...
end

All of this still yields a case sensitive email field when the users sign back in... help?

Upvotes: 2

Views: 100

Answers (1)

lins314159
lins314159

Reputation: 2520

Try this:

self.email.downcase!

Upvotes: 2

Related Questions