Ruby on Rails: Rake aborted!

Asked

Viewed 419 times

1

I’m starting in the world of Rails through the book Ruby on Rails - Put your web app on track.

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

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

And later perform a "rake db:migrate". But when performing, the rake is aborted as per image. Someone could help?

console de erro

Another detail is that when I change uniqueness for unique migration works. What’s the difference between them?

  • An index is usually used Unic, ja the uniqueness is used for validations before Insert for example.

  • Uniquess and validation for record exclusivity. Unique is correct when running a rake db:migrate.

1 answer

1


As @Luizpicolo said, the key uniqueness is only valid in Activerecord validators. The correct key for this case is unique:

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

A correct use of uniqueness would be, for example, in the model User:

class User
  validates :email, uniqueness: true
end

Browser other questions tagged

You are not signed in. Login or sign up in order to post.