Store location with some excluded path This code stores the last know location in the session. The location is not stored if it is one of the exceptions in the if statement. 

def store_location
    if request.fullpath != '/users/sign_in' &amp;&amp;
     request.fullpath != '/users/sign_up' &amp;&amp;
     request.fullpath != '/users/password' &amp;&amp;
     request.fullpath != '/users/sign_out' &amp;&amp;
     request.fullpath != '/accounts' &amp;&amp;
     request.fullpath != '/accounts/new' &amp;&amp;
     !request.fullpath.include?('/users/confirmation') &amp;&amp;
     request.fullpath != '/' &amp;&amp;
     !request.xhr?

     session[:previous_url] = request.fullpath
   end
  end


I need to make it more simple.
this is already simple, it follows Devise wiki: https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update

but if you really want to make it shorter and remove "if" you can use skip_before_filter on controller level, i.e.

class AccountsController &lt; ApplicationController
  skip_before_filter :store_last_page, only: [:new, :index]