1
\$\begingroup\$

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' &&
     request.fullpath != '/users/sign_up' &&
     request.fullpath != '/users/password' &&
     request.fullpath != '/users/sign_out' &&
     request.fullpath != '/accounts' &&
     request.fullpath != '/accounts/new' &&
     !request.fullpath.include?('/users/confirmation') &&
     request.fullpath != '/' &&
     !request.xhr?

     session[:previous_url] = request.fullpath
   end
  end

I need to make it more simple.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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 < ApplicationController
  skip_before_filter :store_last_page, only: [:new, :index]
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I have to say I am surprised that the official docs of Devise advice to use hardcoded paths. \$\endgroup\$
    – tokland
    Commented Jun 11, 2014 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.