【问题标题】:ACL9 and Rails 2.3.8 - NameError: uninitialized constant User::RoleACL9 和 Rails 2.3.8 - NameError: 未初始化的常量 User::Role
【发布时间】:2011-05-15 06:21:04
【问题描述】:

我正在运行 RVM(Ruby 1.8.7-head,Rails 2.3.8)并且正在运行一个新应用程序的基础知识。我有 Authlogic 工作,用最少的代码来工作。我正在尝试使用 ACL9(我正在处理不同的项目,相同的 RVM gemset)

class User < ActiveRecord::Base
    # authentication
  acts_as_authentic
  
  # authorization
  acts_as_authorization_subject
  
  def full_name
    "#{self.first_name} #{self.last_name}"
  end
end

当我尝试运行一个简单的检查以确保 ACL9 正常工作时...

脚本/控制台

u = User.first

u.has_role?(:anyrole)

我收到此错误...

ruby-1.8.7-head > u.has_role?(:anyrole)
NameError: uninitialized constant User::Role
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:105:in `const_missing'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/base.rb:1:in `compute_type'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activesupport-2.3.8/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/base.rb:2230:in `compute_type'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/reflection.rb:156:in `send'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/reflection.rb:156:in `klass'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/reflection.rb:187:in `quoted_table_name'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/associations/has_and_belongs_to_many_association.rb:102:in `construct_sql'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:21:in `initialize'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/associations/has_and_belongs_to_many_association.rb:5:in `initialize'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/associations.rb:1306:in `new'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/activerecord-2.3.8/lib/active_record/associations.rb:1306:in `role_objects'
    from /Users/development/.rvm/gems/ruby-1.8.7-head@rails238/gems/acl9-0.12.0/lib/acl9/model_extensions/for_subject.rb:39:in `has_role?'
    from (irb):2

我不确定为什么这适用于我拥有的所有其他应用程序,但不是这个 - 我不确定错误消息在说什么.. 感谢任何帮助。

【问题讨论】:

    标签: ruby-on-rails acl9


    【解决方案1】:
      class Role < ActiveRecord::Base
        acts_as_authorization_role
      end
    

    【讨论】:

      猜你喜欢
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      相关资源
      最近更新 更多