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.

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top