I’m having trouble seeding my users table.
(rails 3.2.6, jruby 1.6.7.2, devise 2.1.2)
It’s a pretty generic User table, generated by “rails generate devise User”, plus the modifications described by this howto page so that users can login with username instead of email address.
rails db:seed is not giving any indication of error, nor is the log. When I use sqlite console to confirm, the table is empty. Yes, it’s using development environment. I’ve double and triple-checked this.
When I use rails console and enter the creation command, I get this:
1178 ~/dev/proj$ rails console
Loading development environment (Rails 3.2.6)
jruby-1.6.7.2 :001 > User.create(
jruby-1.6.7.2 :002 > :username => 'admin',
jruby-1.6.7.2 :003 > :email => 'admin@fake.com',
jruby-1.6.7.2 :004 > :password => 'admin',
jruby-1.6.7.2 :005 > :password_confirmation => 'admin',
jruby-1.6.7.2 :006 > )
User Exists (1.0ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'admin@x.com' LIMIT 1
=> #<User id: nil, email: "admin@fake.com", encrypted_password: "$2a$10$SMz0xdF.BkPV.4IX4TZ6Zu9WbQEk6kvap7mSGfwA7cLe...", 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, created_at: nil, updated_at: nil, username: "admin">
I’m not sure why it says the user exists, because the table was and is still empty, as shown here:
jruby-1.6.7.2 :013 > User.all
User Load (0.0ms) SELECT "users".* FROM "users"
=> []
It could be that a validation function is malfunctioning. The only one I can find in my source is the find_first_by_auth_conditions one that I copied (as directed) out of the aforementioned-howto page, but that doesn’t look to me like it could be causing this.
I’d appreciate any help. What’s preventing me from creating this user?
Update: If I use the following, it works:
u = User.new(...)
u.save(:validate=>false)
So this means that my validation is failing somewhere. Unfortunately, I haven’t coded any validation aside from the one method I mentioned earlier. How do I resolve that?
Ugh. It turns out that this user’s password was too short.
Looks like the “User Exists” message is actually quite misleading. It gives you the same thing if you create a user where password != confirmation.
Created an issue on the devise project to see if this can be improved.
https://github.com/plataformatec/devise/issues/1985
Edit: And that issue was answered, and I see that I just didn’t know how to read the error messages.