我是Rails的新手,我试图在我的项目中分配一个新的管理员用户。当我在rails控制台中输入AdminUser.all时,出现以下错误:
NameError: uninitialized constant AdminUser
from (irb):1
from /Users/denitalambou/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/console.rb:65:in `start'
from /Users/denitalambou/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/denitalambou/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/denitalambou/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/denitalambou/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
from /Users/denitalambou/Sites/simple_cms/bin/rails:9:in `<top (required)>'
from /Users/denitalambou/.rbenv/versions/2.4.0/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/denitalambou/.rbenv/versions/2.4.0/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
答案 0 :(得分:1)
当您从模型中手动销毁admin_user.db模型时,会发生错误。您将必须使用以下命令销毁整个ActiveAdmin-
rails destroy active_admin:install
然后在没有AdminUser的情况下重新安装ActiveAdmin
rails g active_admin:install --skip-users
答案 1 :(得分:0)
我解决了这个问题。事实证明我忘记了文件名admin_users.rb中的下划线。感谢@margo的帮助。
答案 2 :(得分:0)
我有同样的问题。我删除了活动管理员模型,然后再次运行它,所以出现此错误
NameError: uninitialized constant AdminUser
我解决
您必须确保模型中有admin_user.rb文件
class AdminUser < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :validatable
end
并在admin文件夹中有一个名为admin_users.rb
的文件