I'm following the Devise wiki to redirect the user to the current page after signing in (https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update)
However I'm getting the following error:
Started GET "/login" for 127.0.0.1 at 2014-05-12 18:52:52 -0300
Processing by Devise::SessionsController#new as HTML
←[1m←[35mUser Load (3.0ms)←[0m SELECT "users".* FROM "users" WHERE "users"."id" = 3 ORDER BY "users"."id" ASC LIMIT 1
Redirected to http://localhost:3000/login
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 8ms (ActiveRecord: 3.0ms)
This is the code I have on my Application Controller:
after_filter :store_location
def store_location
# store last url - this is needed for post-login redirect to whatever the user last visited.
if (request.fullpath != "/users/sign_in" &&
request.fullpath != "/users/sign_up" &&
request.fullpath != "/users/password" &&
!request.fullpath.match("/users") &&
!request.xhr? && # don't store ajax calls
request.format == "text/html" || request.content_type == "text/html")
session[:previous_url] = request.fullpath
session[:last_request_time] = Time.now.utc.to_i
end
end
def after_sign_in_path_for(resource)
session[:previous_url] || root_path
end
routes.rb
Myapp::Application.routes.draw do
ActiveAdmin.routes(self)
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations" }, :skip => [:sessions]
as :user do
get 'login' => 'devise/sessions#new', :as => :new_user_session
post 'login' => 'devise/sessions#create', :as => :user_session
delete 'logout' => 'devise/sessions#destroy', :as => :destroy_user_session
end
root 'static_pages#home'
Any idea why this is happening? Thanks