ruby on rails - Redirect loop with Devise after_sign_in_path_for -
i'm having bit of noob issue. wanted devise redirect last page user visited. did following...
def after_sign_in_path_for(resource) request.referer end
works great...except if user logging in through original form causes redirect loop.
i tried
def after_sign_in_path_for(resource) if (request.referer == "/users/sign_in") :pages_home else request.referer end end
but thats not working, because have no idea request.referer returning when encounters original user login page (www.example.com/users/sign_in).
any ideas?
tldr; using devise, want redirect page logged in (i.e /blog/4) unless page /users/sign_in
solved:
matchu right. request.referer returning domain well...
http://example.com/users/sign_in
(note: no www prefix)
i'm still interested in alternative request.referer if insecure or inefficient way.
don't redirect referrers - it's bad idea.
instead, pass next
value across in query-string or form-data. perhaps use like:
def after_sign_in_path_for(resource) params[:next] || super end
when user tries visit page requiring authentication (e.g., /admin/posts/3/edit
) authentication before_filter
issues redirect_to new_session_url(:next => request.path)
. code login action , view preserve :next
query-string parameter.
Comments
Post a Comment