Store location with some excluded path
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]