before_filter with devise

user730569 picture user730569 · May 17, 2011 · Viewed 15.8k times · Source

I'm using Devise's built in before_filter :authenticate_user!. I want to call my own custom method in my application helper if a user fails the before filter (tries to do an action when logged out). How and where can I do this?

Answer

chrismealy picture chrismealy · May 17, 2011

Instead of calling before_filter :authenticate_user! write your own function in your controller that calls authenticate_user!. Something like:

before_filter :logged_in

...

private
def logged_in
  your_function
  authenticate_user!
end