簡體   English   中英

運行rails服務器時出錯

[英]Error when running rails server

我正在嘗試為我的rails博客應用程序配置聲明性授權。 根據需要完成所有操作后,我執行了rails s來啟動服務器。 我遇到了以下錯誤。

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

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

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

編輯:在您關於使用authlogic的評論之后。 這是另一個具有相同錯誤的github頁面:

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

將您的authlogic gem代碼替換為:

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

這是rails的兼容性錯誤。 看看這個帶有錯誤的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 / 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM