我正在關注的設計維基登錄(https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update)設計after_sign_in_path錯誤:過濾器鏈停止:require_no_authentication
但是我得到下面的錯誤後,用戶將當前頁面重定向:
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)
這是代碼我有我的應用程序控制器:
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 != "https://stackoverflow.com/users/sign_in" &&
request.fullpath != "https://stackoverflow.com/users/sign_up" &&
request.fullpath != "https://stackoverflow.com/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'
devise.rb
Devise.setup do |config|
config.secret_key = ENV['DEVISE_SECRET_KEY']
require 'devise/orm/active_record'
# omniauth login
require "omniauth-facebook"
config.omniauth :facebook, ENV["APP_ID"], ENV["APP_SECRET"],
{:scope => 'email, offline_access, user_events, friends_events', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
# add username to login
config.authentication_keys = [ :login ]
config.reset_password_keys = [ :email ]
config.confirmation_keys = [ :login ]
config.case_insensitive_keys = [ :email ]
config.strip_whitespace_keys = [ :email ]
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 10
config.reconfirmable = false
config.password_length = 8..128
config.reset_password_within = 6.hours
config.sign_out_via = :delete
end
你可以發佈你的'routes.rb'和'devise.rb'文件嗎? –
剛剛編輯的問題,謝謝 –