2

So I have ApplicationController.rb:

class ApplicationController < ActionController::Base
  protect_from_forgery

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

and then UsersController.rb:

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

  def show
    #blah blah
  end
end

Now hitting the show action results in:

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

Why isn't that method being inherited so it can be properly used as a before_filter?

Chris
  • 11,819
  • 19
  • 91
  • 145
  • This should work. Could it be that `decode_email` is mistakenly a private method? Do you have `private` somewhere in your `ApplicationController`? – Mischa Dec 29 '12 at 02:08
  • 1
    It is not working exactly because of `private` - it should be private . – R Milushev Dec 29 '12 at 02:43
  • Which ruby and rails versions are you using? Did you try restarting your server? – wpp Dec 29 '12 at 17:58
  • @QumaraSixOneTour, no it SHOULDN'T be private! It should be either public or protected, but not private. – Mischa Dec 30 '12 at 01:58
  • Looks like it should work, but maybe try adding `helper_method :decode_email` above the method in `ApplicationController.rb`. – Brian Jan 02 '13 at 19:58
  • **It works on clean app** for sure in case you described. So the problem is deeper and we need you Application and Users Controllers code to figure out the bug. – makaroni4 Jan 05 '13 at 12:05
  • It is working OK for me, with public or private inherited methods... post your full controllers code to see if we find anything else. – bbonamin Jan 14 '13 at 19:40
  • working for me with private – Tim Kretschmer Jan 15 '13 at 16:56

1 Answers1

0
class ApplicationController < ActionController::Base
  protect_from_forgery

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

is working for me

Tim Kretschmer
  • 2,272
  • 1
  • 22
  • 35