0

레일 블로그 앱에 선언적 권한을 설정하려고합니다. 필요한 모든 작업을 마친 후 레일을 사용하여 서버를 시작했습니다. 다음과 같은 오류가 발생했습니다.레일 서버를 실행할 때 오류가 발생했습니다.

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': 정의되지 않은 지역 변수 또는 메소드 'scope'for ActiveRecord :: Base : Class (NameError) 이것은 오류입니다. '스코프'는 어디에 저장/위치합니까? –

+0

당신이 의미하는 바를 설명 할 수 있다면 좋을 것입니다 .. –

+0

당신은이 오류를 읽었나요? –

답변

2

EDIT : 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에서 "authlogic"보석을 사용했습니다. 충분하지 않니? –

+0

그냥 대답을 언급했는데 –

+1

내 문제가 해결되었습니다. authlogic의 경로를 변경할 필요가 없습니다. 나는 안정된 버전이어야하는 rubyforge에서 가져 가고 있었다. 나는 내 문제를 바로 잡았다. 이제 또 다른 문제는 정의되지 않은 메서드'current_user ' –