Monday 15 September 2014

ruby on rails - session[:previous_url] with endless scrolling -



ruby on rails - session[:previous_url] with endless scrolling -

when user logs in or signs in application redirected page on.

this code in application_controller.rb:

def after_sign_in_path_for(resource) session[:previous_url] || root_path end

the problem i'm using ajax , will_paginate implement endless scrolling. when user has scrolled past first page , login redirected url looks this:

www.example.com/path_=1412539956365&page=6

showing posts on page 6. how redirect to:

www.example.com/path

you utilize regex strip out query strings. here illustration using rails console:

?> session[:previous_url] => www.example.com/path_=1412539956365&page=6 ?> session[:previous_url][/[^\?_]+/] => "www.example.com/path"

you can alter function to:

def after_sign_in_path_for(resource) session[:previous_url][/[^\?_]+/] || root_path end

ruby-on-rails

No comments:

Post a Comment