简体   繁体   中英

ActiveAdmin username or password invalid

I have successfully installed ActiveAdmin on my C9 Ruby on Rails environment but when I entered the default username and password, it came back as “Invalid Email or password.”

Here's what I did:

  • Added gem 'activeadmin', github: 'activeadmin' to my Gemfile
  • Ran bundle install
  • Ran rails generate active_admin:install
  • Start the server with rails server
  • Went to localhost:3000/admin and login screen appeared.

You'll want to go use rails console and create a known admin user.

AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')

Eventually you'd want to move this to your seeds file or something similar.

Go to db/seeds.rb

And you should have the following:

AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password')

and in your console run:

rake db:seed

You can create loads of Admin users here for example:

AdminUser.create!(email: 'admin1@example.com', password: 'password1', password_confirmation: 'password1')
AdminUser.create!(email: 'admin2@example.com', password: 'password2', password_confirmation: 'password2')

And then create the by running rake db:seed in your console.

Lets say you have a Post model, now in your admin/post.rb you need something like this:

ActiveAdmin.register Post do
permit_params :title, :content, :author, :category, :image

show do |t|
  attributes_table do
    row :title
    row :content
    row :author
    row :category
    row :image do
      post.image? ? image_tag(post.image.url, height: '100') : content_tag(:span, "nothing")
    end
  end
end

form :html => {:enctype => "multipart/form-data"} do |f|
  f.inputs do
    f.input :title
    f.input :content
    f.input :author
    f.input :category
    f.input :image, hint: f.post.image? ? image_tag(post.image.url, height: '100') : content_tag(:span, "upload here")
  end
  f.actions
end

end

Make sure you done all the paperclip generating etc

If you look at the source code of active admin, once you run migrations

https://github.com/activeadmin/activeadmin/blob/master/lib/generators/active_admin/devise/devise_generator.rb

create_user_code = "#{class_name}.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password')"

So default user created is admin@example.com with password: password

rails generate active_admin:install adds a line to seed.db to create the default username and password.

So just run rails db:seed and you're good to go.

I'm not sure why this isn't mentioned in the ActiveAdmin setup docs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM