2014-09-06 89 views
0

我已經在Nitrous.io上創建了一個使用Active Admin的導軌應用程序,並且所有工作都在該開發環境中工作。我使用設計/ CanCanCan認證/授權部署的導軌應用程序到Heroku不起作用

當我推到Heroku的,並嘗試訪問主動聯繫,我得到以下錯誤:

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 

Ability.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服務器。

感謝您的幫助球員。

乾杯!

+0

你可以發佈你的ability.rb嗎? – 2014-09-07 06:27:32

+0

嘿@andreydeineko它被添加 – bnussey 2014-09-07 08:33:59

+0

你見過答案嗎?這有幫助嗎? – 2014-09-07 17:02:55

回答

0

好吧終於得到了解決這個問題。問題是由Active Admin創建的默認用戶不包含角色,因此我爲用戶指定了一個角色='管理員',並且能夠與此用戶一起登錄並且一切正常。

感謝您的幫助。