控制器不继承before_filter

时间:2012-12-29 01:23:34

标签: ruby-on-rails ruby actioncontroller

所以我有ApplicationController.rb:

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

现在点击show动作会导致:

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

为什么不继承该方法,以便它可以正确地用作before_filter?

1 个答案:

答案 0 :(得分:0)

class ApplicationController < ActionController::Base
  protect_from_forgery

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

正在为我工​​作