ACL9 和 Rails 2.3.8 - NameError:未初始化常量 User::Role

发布于 2024-10-04 09:59:09 字数 2619 浏览 6 评论 0原文

我正在运行 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 = 用户.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

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

I am running RVM (Ruby 1.8.7-head, Rails 2.3.8) and have the BASICS of a new app running. I have Authlogic working, with the minimal code to make that work. I am attempting to use ACL9 (which I have working on a different project, same 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

When I attempt to just run a simple check to make sure ACL9 is working properly...

script/console

u = User.first

u.has_role?(:anyrole)

I get this error...

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

I'm not sure why this works with every other app I have, but not this one - and I'm not sure what the error message is saying.. any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不念旧人 2024-10-11 09:59:09
  class Role < ActiveRecord::Base
    acts_as_authorization_role
  end
  class Role < ActiveRecord::Base
    acts_as_authorization_role
  end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文