Skip to content

Instantly share code, notes, and snippets.

@chrisyeung1121
Last active August 29, 2015 14:19
Show Gist options
  • Save chrisyeung1121/1bc87d5d941433ebbc4e to your computer and use it in GitHub Desktop.
Save chrisyeung1121/1bc87d5d941433ebbc4e to your computer and use it in GitHub Desktop.
## << Devise::RegistrationController
### Build an user (resource) object from temporary
build_resource(sign_up_params.select{|k,v| v.present?})
# > #<User id: nil, created_at: nil, updated_at: nil, email: "a@b.c", encrypted_password: "$2a$10$HufMLSGEoWzbwhVO.IRztuvE8NKTrQgaXNZthem3wid...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil>
### :validatable module in devise. (took me three hours)
# http://stackoverflow.com/questions/21103138/handle-activerecordrecordnotunique-in-devise-registrations-controller/29792359#29792359
# ActiveRecord::RecordNotUnique in Users::RegistrationsController#create
# PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_email" DETAIL: Key (email)=() already exists. : INSERT INTO "users" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"
## To solve this error, just add :validatable in user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:trackable
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment