【问题标题】:Deployed rails app to Heroku not working将 Rails 应用程序部署到 Heroku 无法正常工作
【发布时间】:2014-09-06 21:24:41
【问题描述】:

我已经在 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 服务器。

感谢你们的帮助。

干杯!

【问题讨论】:

  • 你能发布你的能力.rb吗?
  • 嘿@andreydeineko 添加了
  • 你看到答案了吗?有帮助吗?
  • 嘿伙计,开发环境有一些问题,请参阅下面的 cmets。感谢您的所有帮助

标签: ruby-on-rails heroku activeadmin cancan cancancan


【解决方案1】:

好的,终于找到了解决方案。问题是 Active Admin 创建的默认用户不包含角色,因此我使用角色 = 'administrator' 设置了一个用户,并且能够使用该用户登录并且一切正常。

感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 2018-12-18
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 2014-07-16
    • 1970-01-01
    相关资源
    最近更新 更多