Ruby on Rails: Rake aborted!

1

I'm starting in the Rails world through the Ruby on Rails book - Put your web application on the rails.

After creating a "users" module the guide tells us to add the following command line in the migration:

add_index :users, :email, :uniqueness => true

And then perform a "rake db: migrate". But when performing, the rake is aborted according to the image. Could someone help?

Another detail is that when you switch from uniqueness to unique the migration works. What's the difference between them?

    
asked by anonymous 18.02.2014 / 21:07

1 answer

1

As @LuizPicolo said, key uniqueness is only validated in ActiveRecord validators. The correct key for this case is unique :

add_index :users, :email, :unique => true

Correct use of uniqueness would, for example, be in the User :

class User
  validates :email, uniqueness: true
end
    
19.02.2014 / 00:59