Question

I need to trigger callback before Devise redirects user to login page, probably because authenticate_user! method detected he's not logged in. Something like:

before_filter :authenticate_user!, :only => :edit

def not_authenticated_callback
  # do something
end

It shouldn't be called if authenticate_user! has not been called.

Was it helpful?

Solution

I've found an ugly solution:

around_filter :intersect_warden

def intersect_warden
  success = false
  result = catch(:warden) do
    result = yield
    success = true
    result
  end

  unless success
    not_authenticated_callback
    throw(:warden, result)
  end
end

OTHER TIPS

while using before_filter: authenticate_user! ,the action will not go inside your controller, if the user not logged in.

if you use before_filter, You cant access any functions inside your controller, when the user not logged in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top