1

When i add default users in my rails app via rake task all goes fine, but when i try to login i can't access. Instead, if i sign up via the form, then I can access to the backend of my rails app.

I need to add Users via rake command but I don't understand why I can't login after the users are added to the db.

rails v 3.2.8 devise v 3.2.0

desc "Create a default admin user"
task :default_user => :environment do   
  User.create(name: "myname", email: "my@email.com", login: "mylogin", password: "mypassword", password_confirmation: "mypassword")
end

I use the following modules:

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :encryptable, :encryptor => :restful_authentication_sha1

Since I switched from restful_authentication to devise, I've included

:encryptable, :encryptor => :restful_authentication_sha1

If they are omitted, I suppose that the old users, already present in my users table, can't login, but if a new user is created via rake task, then I can login with it.

Andrew Dev
  • 11
  • 2
  • What is it bootstrap:all task? could you add it? – Adeptus Nov 19 '13 at 10:19
  • The versions of rails and devise would be good too... – hernanvicente Nov 19 '13 at 10:26
  • After i execute rake db:migrate, i populate my tables with a custom rake task. In this task I create my default users (User.create(...)) – Andrew Dev Nov 19 '13 at 10:27
  • 1
    use **create!** in your populator and see if it throws any error. – Nitish Parkar Nov 19 '13 at 10:28
  • The users are added to the table, but after i can't login. Instead if i add a user via sign up form, then i can login. It seems that rake task use a different encryption algorithm – Andrew Dev Nov 19 '13 at 10:31
  • But still we need what do you have in this rake task. maybe you forgot about confirmation or something other. You can edit your question and add it(also version of rails and devise like wrote hernanvicente). – Adeptus Nov 19 '13 at 10:32
  • Look at your users table with `User.all` in your `rails console` and compare the values of the created records from the sign up form against the task records. – hernanvicente Nov 19 '13 at 10:34
  • there are no differences in the records between the two input methods. The length of the passwords are the same and they have the same fields filled – Andrew Dev Nov 19 '13 at 10:42
  • Which modules of devise are active? Are you using confirmable or something else? http://stackoverflow.com/questions/4316940/create-a-devise-user-from-ruby-console – hernanvicente Nov 19 '13 at 10:47
  • I use the following modules: devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :encryptable, :encryptor => :restful_authentication_sha1 – Andrew Dev Nov 19 '13 at 10:49
  • Can you post the create statement you are using? Are you able to execute it from your rails console? – Nitish Parkar Nov 19 '13 at 11:09
  • The crate statemet is the same I've posted in the code above – Andrew Dev Nov 19 '13 at 11:27
  • What error are you getting (also on the console) when logging with a users created via rake? – marzapower Nov 19 '13 at 11:53
  • I get no error; the problem is that I can't login after creation of a User via console or rake. Instead if I create a user via the sign up form, then I can login. In my project I must create a user via rake. – Andrew Dev Nov 19 '13 at 14:05

0 Answers0