user1301037
user1301037

Reputation: 533

Every password fails on Devise Admin model

I followed the first option to create an Admin role as recommended here https://github.com/plataformatec/devise/wiki/How-To:-Add-an-Admin-Role

After that, I created a seed to populate the Admin Model:

Admin.create!([{email: "[email protected]"},
                  {password: "password"},
                  {password_confirmation: "password"}])

Admin Model

class Admin < ApplicationRecord
 devise :database_authenticatable, :trackable, :timeoutable, :lockable 
end

Routes

Rails.application.routes.draw do
 devise_for :admins
end

I tried to sign_in with this password at /admins/sign_in without sucess.

At the rails console I can see the Admin.first, so i don't have idea what im doing worng. Any idea?

Upvotes: 0

Views: 38

Answers (1)

Ren
Ren

Reputation: 1374

Looks like a problem with your syntax. The bracket-types matter.. Right now you are trying to create an admin with an array [ ], where your attributes are divided up into different objects in that array.

Try creating another admin, but this time without the square brackets[ ] and a single hash { }:

Admin.create!({email: "[email protected]",
              password: "password",
              password_confirmation: "password"})

This way you are creating a single Admin object, with the attributes email, password, etc.

If you wanted to create multiple Admins all in one line of code, then you could use an array:

Admin.create!([{email: "[email protected]",
                  password: "password",
                  password_confirmation: "password"},
               {email: "[email protected]",
                  password: "foobar",
                  password_confirmation: "foobar"}])

Upvotes: 1

Related Questions