2010-11-29 7 views
0

レール3で動作していないカスタムプラグインがあります(私はそれを書いていませんでした)が、レール2で動作しました。カスタム認証方式で、ここにメインモジュールの外観を示します。Rails 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

012にはActionController::Verificationモジュールがあったため、2.3で動作しました。このモジュールが存在しないため、3.0では動作しません。むしろあなたがにフックすることができ、モジュールを持っているのRailsに頼るよりも、このように独自に定義する:

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(:含まれ、あなたの:: MOD)

その機能を利用できるようにする。 ActiveSupport::Concernは、モジュール内にClassMethodsInstanceMethodsモジュールをサポートしており、モジュールが含まれているものの正しい領域にこれらのモジュールのメソッドをロードします。

関連する問題