我已经在 Nitrous.io 上使用 Active Admin 创建了一个 rails 应用程序,并且一切都在该开发环境中工作。我正在使用 Devise/CanCanCan 进行身份验证/授权
当我推送到 heroku 并尝试访问 Active Admin 时,我收到以下错误:
Started GET "/admin" for 91.226.23.198 at 2014-09-06 21:15:49 +0000
Processing by Admin::ProductsController#index as HTML
NoMethodError (undefined method `include?' for nil:NilClass):
app/models/user.rb:8:in `role?'
app/models/ability.rb:6:in `initialize'
我的用户模型是这样的:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable
def role?(r)
role.include? r.to_s
end
end
能力.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.role? :administrator
can :manage, :all
elsif user.role? :moderator
can :manage, Product
can :manage, User, :id => user.id
cannot :destroy, User
#can :read, ActiveAdmin::Page, :name => "Dashboard"
can :read, ActiveAdmin::Page, :name => "Contact Us"
can :read, ActiveAdmin::Page, :name => "About x"
can :read, ActiveAdmin::Page, :name => "FAQ"
#can :manage, [Page, Unit, Category, News]
else
can :read, Product
can :manage, User, :id => user.id
cannot :destroy, User
#can :read, ActiveAdmin::Page, :name => "Dashboard"
can :read, ActiveAdmin::Page, :name => "Contact Us"
can :read, ActiveAdmin::Page, :name => "About x"
can :read, ActiveAdmin::Page, :name => "FAQ"
end
end
end
我究竟做错了什么?
我试过多次重启heroku服务器。
谢谢你们的帮助。
干杯!