代码之家  ›  专栏  ›  技术社区  ›  Rabbott

ACL9和Rails 2.3.8-名称错误:未初始化常量user::role

  •  2
  • Rabbott  · 技术社区  · 14 年前

    我运行的是RVM(Ruby1.8.7-head,Rails2.3.8),并掌握了新应用程序运行的基础知识。我让AuthLogic工作,用最少的代码使其工作。我正在尝试使用ACL9(我在另一个项目中工作过,同一个RVM gemest)

    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=用户优先

    你扮演什么角色?(:任何角色)

    我得到这个错误…

    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
    

    我不知道这为什么能和我拥有的其他应用程序一起使用,但不是这个——我也不知道错误消息是什么意思。感谢您的帮助。

    1 回复  |  直到 11 年前
        1
  •  2
  •   chris Frisina    11 年前
      class Role < ActiveRecord::Base
        acts_as_authorization_role
      end
    
    推荐文章