2010-12-20 14 views
3

私はRailsアプリケーションを作成していますが、私はそれを必要とする各コントローラの上部に私のカスタムエラークラスを呼び出すのではなく、それをモジュールの中に置き、そのモジュールだけを含んでいました。Rails 3 rescue_from、カスタムモジュールを使用して作業しています

の作業コード(モジュール):

module ApiException 
    class EmptyParameter < StandardError 
    end 
end 

の作業コード(コントローラー):私は私のカスタムモジュール内のメソッドを呼び出す方法:withコマンドを使用して、私の質問は、

ここ
# include custom error exception classes 
    include ApiException 

    rescue_from EmptyParameter, :with => :param_error 

    # rescure record_not_found with a custom XML response 
    rescue_from ActiveRecord::RecordNotFound, :with => :active_record_error 

    def param_error(e) 
     render :xml => "<error>Malformed URL. Exception: #{e.message}</error>" 
    end 

    def active_record_error(e) 
     render :xml => "<error>No records found. Exception: #{e.message}</error>" 
    end 

です?このような

何か:rescue_from EmptyParameter, :with => :EmptParameter.custom_class

+0

はFYIそのrescue_fromはまだ似たような自分自身をしようとRailsの3で動作していません。 lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror – JohnMetta

答えて

2

あなたはこのような何かを試すことができます。https://レール

rescue_from EmptyParameter do |exception| 
    EmptyParameter.custom_class_method 
end 
関連する問題