我们正在使用带有rails 3.2和活动管理员0.6.3的Ruby 2.1。我们的网站在前端启动并运行,但在尝试访问管理面板时,它说:
"NoMethodError (undefined method `authenticate_admin_user!' for Admin::DashboardController"
我尝试在网上搜索解决方案,但没有一个能够解决问题。
有什么建议吗?
修改:管理员用户模型
ActiveAdmin.register AdminUser do
#menu :priority => 2
menu false
index :title => 'Admin Users'+SiteSetting.site_title do
column :email
column :role do |show|
if show.role=="superadmin"
status_tag('Super Admin', :ok)
elsif show.role=="subadmin"
status_tag('Sub Admin', :ok)
elsif show.role=="customeadmin"
status_tag('Custom Admin', :ok)
else
status_tag('Normal Admin', :ok)
end
end
column 'Current Login', :current_sign_in_at
column 'Last Login', :last_sign_in_at
column 'Login count', :sign_in_count
#current_admin_user[:id]
@count = AdminUser.count
if @count == 1
column do |show|
links = link_to 'View', {:action => show.id.to_s}
links += ' '
links += link_to 'Edit', {:action => show.id.to_s+'/edit'}
links
end
else
default_actions
end
end
controller do
def password
render :text => 'test'
end
def new
@admin_user = AdminUser.new
end
def create
@temp = params[:admin_user][:role_permission]
if @temp ==nil
else
@new_per = @temp.join(',')
params[:admin_user][:role_permission] = @new_per
end
@admin_user = AdminUser.new(params[:admin_user])
@admin_user.save
redirect_to(:action => 'index')
end
def edit
@admin_user = AdminUser.find(params[:id])
end
end
filter :email
sidebar :AdminUserRights do
ul do
li "Super Admin: Can Manage All Pages"
li "Sub Admin: Can Only View And Update All Pages"
li "Normal Admin: Can Only View All Pages"
li "Custom Admin: Customize your admin via giving them custom rights of links"
end
end
form :html => { :enctype => "multipart/form-data" } do |f|
render "create" , :layout => 'active_admin'
end
end
我在应用程序控制器文件中添加了此代码。
编辑:应用程序控制器
def authenticate_active_admin_user!
authenticate_admin_user!
unless current_admin_user.role?(:superadmin)
flash[:alert] = "You are not authorized to access this resource!"
redirect_to root_path
end
end