(Edit: added development.log logs, "Unpermitted parameters: email")
Devise was working fine but I deleted all users using rails console and tried to make a new user. I get an error that email can't be blank. When I remove the :validatable block I get this error.
I tried to go back to commits but the error exists on all other commits. I am not sure if its something to do with the database.
My project can be found here (I pushed the last commit). I am not sure where the problem is and what I can copy for devise. I have put some code here which may show the problem.
I was able to create a user through rails console using:
u = User.new(:email => "user#name.com", :username => "test", :password => 'password', :password_confirmation => 'password')
u.save
Logs when trying to signup:
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"WQkgKxF8rIB1wAq8vnz4Y0bCv9Txlyv0eO8IyEmpEAk=", "user"=>{"email"=>"user#example.com", "username"=>"test", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Unpermitted parameters: email
User.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :provide, :uid, :name, :email, :password, :password_confirmation, :remember_me, :username
validates_presence_of :username
has_many :posts
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname
end
end
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
def password_required?
super && provider.blank?
end
def update_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
else
super
end
end
end
schema.rb
ActiveRecord::Schema.define(:version => 20131118165834) do
create_table "photo_posts", :force => true do |t|
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
create_table "posts", :force => true do |t|
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "content_type"
t.integer "content_id"
end
add_index "posts", ["content_type", "content_id"], :name => "index_posts_on_content_type_and_content_id"
add_index "posts", ["user_id"], :name => "index_posts_on_user_id"
create_table "title_posts", :force => true do |t|
t.string "body"
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0, :null => false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "username"
t.string "provider"
t.string "uid"
t.string "name"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end
logs:
Started POST "/users" for 127.0.0.1 at 2013-11-24 00:23:12 +0000
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"awAC+Cn3qQgv2kMwZOlH8Zo60BuV4T41OnKjgvKeytE=", "user"=>{"email"=>"user#example.com", "username"=>"stttt", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Unpermitted parameters: email
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
[1m[35m (0.0ms)[0m rollback transaction
Rendered devise/shared/_links.erb (1.0ms)
Rendered devise/registrations/new.html.erb within layouts/application (15.0ms)
Rendered layouts/_header.html.erb (4.0ms)
Rendered layouts/_footer.html.erb (0.0ms)
Completed 200 OK in 178.0ms (Views: 72.0ms | ActiveRecord: 0.0ms)
Found what the error is. I use strong parameters and that causes an error. More at https://github.com/plataformatec/devise#strong-parameters
So the solution is to add this into your application_controller.rb
# Rails 3.x.x and older
before_filter :configure_permitted_parameters, if: :devise_controller?
# Rails 4.x.x and newer
before_action :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation) }
end
Keep in mind to configure for each action like :sign_in, :sign_up, :account_update etc.
The above answer is different for Devise 4 and Rails 5 now.
According to the documentation:
The Parameter Sanitaizer API has changed for Devise 4
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
end
end
Rails 5, Undefined method `for' for #<Devise on line devise_parameter_sanitizer.for
Related
I'm trying to build a RESTFul API with devise & jwt.
I can register, and login/logout using my jwt bear token, using Postman.
Now I have a problem when I want to POST an Article.
I dont understand why my console goes for a login after I POST an Article with Postman.
Also I dont understand why I get this 401 error. It's really hard to find some content with RESTFul + API + Devise + JWT.
Do you think it's better in the long term to run with or without Devise ? Cause there is actually some content without Devise.
What I try on Postman
Authorization : <Bearer token>
{
"title":"the title",
"content":"the content"
}
Returned ERROR message from the console when I post an Article with Postman ( and with a the same bear token as for login/logout
Started POST "/articles" for ::1 at 2021-09-01 18:07:41 +0200
Processing by ArticlesController#create as */*
Parameters: {"title"=>"the title", "content"=>"the content", "article"=>{"title"=>"the title", "content"=>"the content"}}
Completed 401 Unauthorized in 76ms (Allocations: 113)
Started GET "/api/login" for ::1 at 2021-09-01 18:07:41 +0200
Processing by SessionsController#new as JSON
Completed 200 OK in 71ms (Views: 2.5ms | Allocations: 179)
app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
before_action :set_todo, only: [:show, :update, :destroy]
before_action :authenticate_user!
# GET /todos
def index
#articles = Article.all
json_response(#articles)
end
# POST /todos
def create
#article = Article.create!(article_params)
#article.user = current_user
end
# GET /todos/:id
def show
json_response(#article)
end
# PUT /todos/:id
def update
#article.update(article_params)
head :no_content
end
# DELETE /todos/:id
def destroy
#article.destroy
head :no_content
end
private
def article_params
# whitelist params
params.permit(:title, :content, :user_id)
end
def set_article
#article = Article.find(params[:id])
end
end
db/shema.rb
ActiveRecord::Schema.define(version: 2021_09_01_124211) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "content"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "user_id", null: false
t.index ["user_id"], name: "index_articles_on_user_id"
end
create_table "jwt_denylist", force: :cascade do |t|
t.string "jti", null: false
t.datetime "expired_at", null: false
t.index ["jti"], name: "index_jwt_denylist_on_jti"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
add_foreign_key "articles", "users"
end
app/models/article.rb
class Article < ApplicationRecord
belongs_to :user
end
app/models/user.rb
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:jwt_authenticatable, jwt_revocation_strategy: JwtDenylist
has_many :articles
end
Just started learning ruby on rails, and i created a simple shopping cart application but when i click "add to cart", i get a rollback transaction from my server. I believe the error has something to do with my orderitem controller but not sure how to fix this issue here my code.
rails server
Started POST "/order_items" for 127.0.0.1 at 2017-10-25 10:47:44 -0400
Processing by OrderItemsController#create as JS
Parameters: {"utf8"=>"✓", "order_item"=>{"product_id"=>"13", "quantity"=>"1"}, "commit"=>"Add to cart"}
(0.0ms) begin transaction
Product Load (0.5ms) SELECT "products".* FROM "products" WHERE "products"."id" = ? LIMIT ? [["id", 13], ["LIMIT", 1]]
(0.0ms) rollback transaction
Rendering order_items/create.js.erb
Rendered order_items/create.js.erb (0.5ms)
Completed 200 OK in 1028ms (Views: 605.5ms | ActiveRecord: 0.5ms)
order_items_controller.rb
class OrderItemsController < ApplicationController
def create
#order = current_order
#order_item = #order.order_items.new(order_item_params)
#order.save
session[:order_id] = #order.id
end
def update
#order = current_order
#order_item = #order.order_items.new(order_item_params)
#order_item.update_attributes(order_item_params)
#order_items = #order.order_items
end
def destroy
#order = current_order
#order_item = #order.order_items.find(params[:id])
#order_item.destroy
#order_items = #order.order_items
end
private
def order_item_params
params.require(:order_item).permit(:product_id, :quantity)
end
end
create.js.erb
<% if #order.errors.any? || #order_item.errors.any? %>
alert("Invalid")
<% else %>
$(".cart").html("<%= escape_javascript(render 'layouts/cart') %>")
<% end %>
schema.rb
ActiveRecord::Schema.define(version: 20171019015705) do
create_table "order_items", force: :cascade do |t|
t.integer "product_id"
t.integer "order_id"
t.integer "quantity"
t.float "total_price"
t.float "unit_price"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "orders", force: :cascade do |t|
t.float "subtotal"
t.float "total"
t.float "shipping"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end
create_table "products", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.float "price"
t.text "description"
t.string "picture"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "username"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
end
orderItem.rb
class OrderItem < ApplicationRecord
belongs_to :order
belongs_to :product
before_save :set_unit_price
before_save :set_total_price
def unit_price
if persisted?
self[:unit_price]
else
product.price
end
end
def total_price
unit_price * quantity
end
private
def set_unit_price
self[:unit_price] = unit_price
end
def set_total_price
self[:total_price] = quantity * set_unit_price
end
end
order.rb
class Order < ApplicationRecord
has_many :order_items
belongs_to :user
before_save :set_subtotal
def subtotal
order_items.collect {|order_item| order_item.valid? ? (order_item.unit_price*order_item.quantity) : 0}.sum
end
private
def set_subtotal
self[:subtotal] = subtotal
end
end
user.rb
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :orders
def to_param
username
end
end
carts_controller.rb
class CartsController < ApplicationController
before_action :authenticate_user!
def show
#order_items = current_order.order_items
end
end
Rails Server now
Started GET "/products" for 127.0.0.1 at 2017-10-25 11:21:11 -0400
Processing by ProductsController#index as HTML
Rendering products/index.html.erb within layouts/application
Product Load (0.0ms) SELECT "products".* FROM "products"
Rendered products/index.html.erb within layouts/application (16.0ms)
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]]
Rendered layouts/_cart.html.erb (1.0ms)
Rendered layouts/_nav.html.erb (34.3ms)
Completed 200 OK in 604ms (Views: 571.1ms | ActiveRecord: 0.5ms)
#order_item = #order.order_items.new(order_item_params)
is creating an item only in memory. there is nothing wrong with that.but i think you need to change the new to create as so
#order_item = #order.order_items.create(order_item_params)
I'm trying to add some extra information to my Devise User model like first_name, last_name, age, gender and city.
When I fill the signup form and click to submit I get this error:
SQLite3::ConstraintException: NOT NULL constraint failed: users.first_name: INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?)
def each
loop do
val = step
break self if done?
yield val
end
And these are the parameters if they are any use:
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"2e5oUwMw84HtwSuI09X1O5kjPLYk7SW4VKgGOOxcB93W7sSQYjPgq3N/BGo0+oAEifhec4lQ3PUt9vub17vs7g==",
"user"=>
{"first_name"=>"Test", "last_name"=>"Test", "age"=>"69", "city"=>"New York", "gender"=>"Trans", "email"=>"test.test#email.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"},
"commit"=>"Sign up"}
Here is my schema.rb just in case:
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.string "first_name", null: false
t.string "last_name", null: false
t.integer "age", null: false
t.string "city", null: false
t.string "gender", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Here is my user.rb model too:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
To have additional columns on user not already set in devise I allowed access in my ApplicationContoller this way. Rails4
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
# Only add some parameters
devise_parameter_sanitizer.for(:accept_invitation).concat [:first_name, :last_name]
end
or
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :full_name
end
and this would allow you to have first_name last_name with the other things that you have set up.
Rails5
def configure_permitted_parameters
additional_params = [:name, :company, :email_confirmation, {addresses_attributes: [:address1, :address2, :city, :state, :zip, :country, :name]}]
devise_parameter_sanitizer.permit(:sign_up, keys: additional_params)
devise_parameter_sanitizer.permit(:account_update, keys: additional_params)
end
You have a unique index on email. What the error is saying is that the email you are trying to save is not null in the database. A user already has this email. Change the email and it should work.
# to check for the user in the database
rails c
user = User.find_by_email("test.test#email.com") should bring back a user.
I have followed the documentation online, however I am still struggling and I don't know where I went wrong. When I am trying to sign a user up, all I am seeing is 'please review the problems below' upon them submitting, which isn't even being displayed.The terminal also isn't saying much.
Application Controller:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
added_attrs = [:username, :email, :password, :password_confirmation, :remember_me]
devise_parameter_sanitizer.permit :sign_up, keys: [:username, :password]
devise_parameter_sanitizer.permit :account_update, keys: [:username, :password]
end
end
User model:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :stories
validates :username, :presence => true, :uniqueness => { :case_sensitive => false}
validates_format_of :username, with: /^[a-zA-Z0-9_\.]*$/, :multiline => true
attr_accessor :login
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :authentication_keys => {email: true, login: false}
def self.find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions.to_h).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
elsif conditions.has_key?(:username) || conditions.has_key?(:email)
where(conditions.to_h).first
end
end
end
In the terminal:
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"sTFYfOW5txc1AYinMyWDdaMfggAGh1oX/JSrR7vXc25cEwW5krezOQ6V5zE6QLXI6Dmwi8X3LN8s91rahJBxww==", "user"=>{"username"=>"indigo", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
(0.1ms) begin transaction
User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."username") = LOWER(?) LIMIT ? [["username", "indigo"], ["LIMIT", 1]]
(0.1ms) rollback transaction
Rendering users/registrations/new.html.erb within layouts/application
Rendered users/shared/_links.html.erb (1.3ms)
Rendered users/registrations/new.html.erb within layouts/application (8.7ms)
/home/benjamin/Desktop/projectoxygen/app/views/layouts/application.html.erb:47: warning: else without rescue is useless
Completed 200 OK in 306ms (Views: 42.4ms | ActiveRecord: 0.4ms)
devise db file:
class DeviseCreateUsers < ActiveRecord::Migration[5.0]
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
change_column :users, :email, uniqueness: false
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end
current errors:
ActiveRecord::RecordNotUnique in Devise::RegistrationsController#create
SQLite3::ConstraintException: UNIQUE constraint failed: users.email: INSERT INTO "users" ("encrypted_password", "created_at", "updated_at", "username") VALUES (?, ?, ?, ?)
terminal:
ActiveRecord::RecordNotUnique in Devise::RegistrationsController#create
SQLite3::ConstraintException: UNIQUE constraint failed: users.email: INSERT INTO "users" ("encrypted_password", "created_at", "updated_at", "username") VALUES (?, ?, ?, ?)
If you are using username instead of email as authentication key, then you must have defined:
#config/initializers/devise.rb
config.authentication_keys = [:username]
-
OR, you can define authentication key in model also as:
devise :database_authenticatable, :authentication_keys => [:username]
Add the following methods to model User in order to avoid validations for email:
def email_required?
false
end
def email_changed?
false
end
If you have a UNIQUE constraint over the email column, then create a migration to remove index on email column:
def change
remove_index :users, :email
end
First I'm quite new to ruby and rails...
I have a little application working with devise 1.5.4. I tried to upgrade to 2.0 but now authentication is failing in development mode (tests seem to be ok !?).
I searched the web quite extensively I think but found nothing. So I tried debugging (first time in ruby :) : the only thing that occured to me is that the only devise "strategy" used is rememberable and that there is no access to the database in the log.
log:
Started POST "/users/sign_in" for 127.0.0.1 at 2012-02-17 15:47:22 +0100
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"B0YUlSTdLU5vHkSuB4n78rM4ikyiLzTR0PgZmkSVzro=", "user"=>{"email"=>"member001#labandprocess.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Completed 401 Unauthorized in 52ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"B0YUlSTdLU5vHkSuB4n78rM4ikyiLzTR0PgZmkSVzro=", "user"=>{"email"=>"member001#labandprocess.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Rendered devise/_links.erb (0.4ms)
Rendered devise/sessions/new.html.erb within layouts/application (5.7ms)
Rendered shared/_header.html.erb (4.5ms)
Rendered shared/_messages.html.erb (0.1ms)
Rendered shared/_footer.html.erb (27.2ms)
Rendered shared/_user_status.html.erb (0.1ms)
Completed 200 OK in 194ms (Views: 57.6ms | ActiveRecord: 2.1ms)
I made a diff between the 2 versions of my application, and the only thing that has changed beside the views and devise.rb (which is in both case the default one, i'm quite sure) is the migration :
After (2.0):
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Encryptable
# t.string :password_salt
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
## Token authenticatable
# t.string :authentication_token
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :confirmation_token, :unique => true
add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
Before (1.5) :
def change
create_table(:users) do |t|
t.confirmable
t.database_authenticatable :null => false
t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
t.recoverable
t.rememberable
t.trackable
# t.encryptable
# t.token_authenticatable
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :confirmation_token, :unique => true
add_index :users, :unlock_token, :unique => true
#add_index :users, :authentication_token, :unique => true
end
and I seed data in dev mode with this:
User.create!(
:email => 'member001#xxx.com',
:password => 'mmmmmm'
).confirm!
thanks for your help!
Well, after several hours of comparison, I came to the conclusion that maybe the version of rails is the culprit. I was using 3.1.3 but after upgrading to 3.2.1 (with some other dependencies: i18n_routing and kaminari) it's working...
this is certainly not the main reason since the devise documentation states that rails 3.1
is compatible with devise 2.0, but it's working for now :)