我有以下abilities
型号:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user, not logged in.
if user.role? == :admin
can :manage, :all
else
can :read, :all
end
if user.role == "default"
can :create, Homescreen
end
can :destroy, Homescreen do |homescreen|
homescreen.try(:user) == user
end
end
end
我有以下用户模型:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
before_create :setup_default_role_for_new_users
attr_accessible :email, :password, :password_confirmation, :remember_me
has_many :homescreens
ROLES =%w[admin default]
private
def setup_default_role_for_new_users
if self.role.blank?
self.role = "default"
end
end
end
当我在本地计算机上运行时,它运行正常。
但是,当我部署到heroku时,我收到以下错误:
GET URL.herokuapp.com dyno=web.1 queue=0 wait=0ms service=158ms status=500 bytes=643
app/models/ability.rb:7:in `initialize'
NoMethodError (undefined method `role?' for #<User:0x00000003b56050>):
cache: [GET /] miss
Started GET "/" for my-ipaddress at 2012-03-19 16:14:38 +0000
NoMethodError (undefined method `role?' for #<User:0x00000003df5d88>):
app/models/ability.rb:7:in `initialize'
cache: [GET /] miss
我做错了什么?
答案 0 :(得分:2)
我使用以下命令重新启动了heroku:
heroku restart && heroku ps:restart
然后工作正常。