2012-12-29 36 views
2

所以我有ApplicationController.rb:控制器不繼承的before_filter

class ApplicationController < ActionController::Base 
    protect_from_forgery 

    def decode_email 
    params[:email] = URI::decode(params[:email]) 
    end 
end 

然後UsersController.rb:

class UsersController < ApplicationController 
    before_filter :decode_email, only: [:show] 

    def show 
    #blah blah 
    end 
end 

現在打在表演動作的結果:

undefined local variable or method 'decode_email' for #<UsersController:0x007fb5f216a710> 

爲什麼是不是該方法被繼承,所以它可以被正確地用作before_filter?

+0

這應該工作。難道'decode_email'是錯誤的私人方法嗎?你在'ApplicationController'的某處有'private'嗎? – Mischa

+1

由於「private」而不能正常工作 - 它應該是私人的。 –

+0

您使用的是哪種ruby和rails版本?你有沒有嘗試重新啓動你的服務器? – wpp

回答

0
class ApplicationController < ActionController::Base 
    protect_from_forgery 

    private 
    def decode_email 
     params[:email] = URI::decode(params[:email]) 
    end 
end 

爲我工作