문제

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