2010-11-29 2 views
0

레일 3에서 작동하지 않는 커스텀 플러그인이 있습니다 (필자는 쓰지 않았습니다). 그러나 레일 2에서 작동했습니다. 다음은 기본 모듈의 모습입니다.레일 3 - 플러그인이 '정의되지 않은 로컬 변수'를 반환합니다.

#lib/auth.rb 
module ActionController 

    module Verification 
    module ClassMethods 
     def verify_identity(options = {}) 
     class_eval(%(before_filter :validate_identity, :only => options[:only], :except => options[:except])) 
     end 
    end 
    end 

    class Base 
    #some configuration variables in here 

    def validate_identity 
     #does stuff to validate the identity 
    end 
    end 

end 

#init.rb 
require 'auth' 
require 'auth_helper' 
ActionView::Base.send(:include, AuthHelper) 

AuthHelper는 그룹 구성원 기반의 인증을위한 간단한 도우미 방법을 포함합니다.

내가 actioncontroller에 'verify_identity'를 포함

: TestController에 대한 정의되지 않은 지역 변수 또는 메소드`verify_identity ':

class TestController < ApplicationController 
    verify_identity 
    .... 
end 

나는 라우팅 오류 클래스. 어떻게하면이 문제를 해결할 수 있을까요? 감사!

답변

3

거기에 ActionController::Verification 모듈이 있었기 때문에 2.3에서 작동했습니다. 이 모듈이 없기 때문에 3.0에서 작동하지 않습니다. 오히려 당신이에 연결할 수 있습니다 모듈을 가지고 레일에 의존하지 않고, 정의 자신의이 같은 :

require 'active_support/concern' 
module Your 
    module Mod 
    extend ActiveSupport::Concern 
    module ClassMethods 
     def verify_identity(options = {}) 
     # code goes here 
     end 
    end 
    end 
end 

을 사용 :

ActionController :: Base.send (: 포함, 귀하의 :: 모)

해당 기능을 사용할 수 있도록 설정하십시오. ActiveSupport::Concern은 모듈 내부에 ClassMethodsInstanceMethods 모듈을 지원하며 모듈이 포함되어있는 영역의 올바른 영역에이 모듈의 메소드로드를 처리합니다.

관련 문제