0

我正在嘗試爲我的rails博客應用程序配置聲明授權。根據需要完成所有工作後,我開始使用rails來啓動服務器。我遇到了以下錯誤。運行rails服務器時出錯

rails s 
/var/lib/gems/1.8/gems/activerecord-3.2.9/lib/active_record/dynamic_matchers.rb:50:in `method_missing': undefined local variable or method `scopes' for ActiveRecord::Base:Class (NameError) 
    from /var/lib/gems/1.8/gems/declarative_authorization-0.5.2/lib/declarative_authorization/in_model.rb:37:in `included' 
    from /var/lib/gems/1.8/gems/declarative_authorization-0.5.2/lib/declarative_authorization/in_model.rb:36:in `module_eval' 
    from /var/lib/gems/1.8/gems/declarative_authorization-0.5.2/lib/declarative_authorization/in_model.rb:36:in `included' 
    from /var/lib/gems/1.8/gems/declarative_authorization-0.5.2/lib/declarative_authorization.rb:17:in `include' 
    from /var/lib/gems/1.8/gems/declarative_authorization-0.5.2/lib/declarative_authorization.rb:17:in `send' 
    from /var/lib/gems/1.8/gems/declarative_authorization-0.5.2/lib/declarative_authorization.rb:17 
    from /var/lib/gems/1.8/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require' 
    from /var/lib/gems/1.8/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require' 
    from /var/lib/gems/1.8/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each' 
    from /var/lib/gems/1.8/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `require' 
    from /var/lib/gems/1.8/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each' 
    from /var/lib/gems/1.8/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require' 
    from /var/lib/gems/1.8/gems/bundler-1.2.3/lib/bundler.rb:128:in `require' 
    from /blogging/config/application.rb:7 
    from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands.rb:53:in `require' 
    from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands.rb:53 
    from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap' 
    from /var/lib/gems/1.8/gems/railties-3.2.9/lib/rails/commands.rb:50 
    from script/rails:6:in `require' 
    from script/rails:6 

我的博客應用程序有點類似於這個blog應用程序。

請幫助解決此問題。謝謝。 :) -

+0

'method_missing':未定義的ActiveRecord :: Base:Class(NameError)的局部變量或方法'範圍'這是錯誤。只要看看'範圍'存儲/位置在哪裏? – 2013-05-02 10:24:29

+0

如果你能解釋你的意思,那會很好。 – 2013-05-02 10:34:44

+0

你看過錯誤嗎? – 2013-05-02 10:37:17

回答

2

編輯:關於使用authlogic的評論後。這裏有一個具有相同錯誤的另一github上頁:

https://github.com/binarylogic/authlogic/issues/316

取代你authlogic寶石的代碼如下:

gem "authlogic", :git => "git://github.com/binarylogic/authlogic.git" 

這是一個軌道兼容性錯誤。看看這個頁面GitHub的與錯誤:

https://github.com/stffn/declarative_authorization/issues/102

他們已經通過編輯LIB固定它/ declarative_authorization/in_model.rb

def self.included(base) # :nodoc: 
     #base.extend(ClassMethods) 
     base.module_eval do 
-  scopes[:with_permissions_to] = lambda do |parent_scope, *args| 
-   options = args.last.is_a?(Hash) ? args.pop : {} 
-   privilege = (args[0] || :read).to_sym 
-   privileges = [privilege] 
-   context = 
-    if options[:context] 
-    options[:context] 
-    elsif parent_scope.respond_to?(:proxy_reflection) 
-    parent_scope.proxy_reflection.klass.name.tableize.to_sym 
-    elsif parent_scope.respond_to?(:decl_auth_context) 
-    parent_scope.decl_auth_context 
-    else 
-    parent_scope.name.tableize.to_sym 
-    end 
-   
-   user = options[:user] || Authorization.current_user 
+  if Rails.version < "3.1" 
+   scopes[:with_permissions_to] = lambda do |parent_scope, *args| 
+   options = args.last.is_a?(Hash) ? args.pop : {} 
+   privilege = (args[0] || :read).to_sym 
+   privileges = [privilege] 
+   context = 
+    if options[:context] 
+     options[:context] 
+    elsif parent_scope.respond_to?(:proxy_reflection) 
+     parent_scope.proxy_reflection.klass.name.tableize.to_sym 
+    elsif parent_scope.respond_to?(:decl_auth_context) 
+     parent_scope.decl_auth_context 
+    else 
+     parent_scope.name.tableize.to_sym 
+    end 

-   engine = options[:engine] || Authorization::Engine.instance 
-   engine.permit!(privileges, :user => user, :skip_attribute_test => true, 
-       :context => context) 
+   user = options[:user] || Authorization.current_user 
+ 
+   engine = options[:engine] || Authorization::Engine.instance 
+   engine.permit!(privileges, :user => user, :skip_attribute_test => true, 
+       :context => context) 

-   obligation_scope_for(privileges, :user => user, 
-    :context => context, :engine => engine, :model => parent_scope) 
+   obligation_scope_for(privileges, :user => user, 
+    :context => context, :engine => engine, :model => parent_scope) 
+   end 
     end 

     # Builds and returns a scope with joins and conditions satisfying all obligations. 
@@ -96,7 +98,32 @@ def self.obligation_scope_for(privileges, options = {}) 
     # current user. 
     # 
     def self.with_permissions_to (*args) 
-   scopes[:with_permissions_to].call(self, *args) 
+   if Rails.version < "3.1" 
+   scopes[:with_permissions_to].call(self, *args) 
+   else 
+   options = args.last.is_a?(Hash) ? args.pop : {} 
+   privilege = (args[0] || :read).to_sym 
+   privileges = [privilege] 
+ 
+   parent_scope = scoped 
+   context = 
+    if options[:context] 
+     options[:context] 
+    elsif parent_scope.klass.respond_to?(:decl_auth_context) 
+     parent_scope.klass.decl_auth_context 
+    else 
+     parent_scope.klass.name.tableize.to_sym 
+    end 
+ 
+   user = options[:user] || Authorization.current_user 
+ 
+   engine = options[:engine] || Authorization::Engine.instance 
+   engine.permit!(privileges, :user => user, :skip_attribute_test => true, 
+       :context => context) 
+ 
+   obligation_scope_for(privileges, :user => user, 
+    :context => context, :engine => engine, :model => parent_scope.klass) 
+   end 
     end 

     # Activates model security for the current model. Then, CRUD operations 

和測試/ test_helper.rb中的文件:

 map.connect ':controller/:action/:id' 
    end 
else 
- Rails::Application.routes.draw do 
+ #Rails::Application.routes.draw do 
+ Rails.application.routes.draw do 
    match '/name/spaced_things(/:action)' => 'name/spaced_things' 
    match '/deep/name_spaced/things(/:action)' => 'deep/name_spaced/things' 
    match '/:controller(/:action(/:id))' 
@@ -146,7 +147,8 @@ def request! (user, action, reader, params = {}) 

    unless Rails.version < "3" 
    def setup 
-  @routes = Rails::Application.routes 
+  #@routes = Rails::Application.routes 
+  @routes = Rails.application.routes 
    end 
    end 
end 
+0

我只在我的gemfile中使用了gem「authlogic」。這還不夠嗎? – 2013-05-02 11:45:01

+0

只是嘗試我提到的 – 2013-05-02 11:47:33

+1

我的問題與您的答案解決。無需更改authlogic的路徑。我從rubyforge應該是一個穩定的版本。我糾正了我的問題。現在另一個問題,未定義的方法'current_user' – 2013-05-02 12:18:57