2014-05-12 3 views
0

나는 다음과 같은 오류 받고 있어요 그러나 after_sign_in_path 오류를 고안 : 필터 체인은 중단 : require_no_authentication

(https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update)

로그인 후 현재 페이지로 사용자를 리디렉션하기 위해 고안 위키 다음 해요 :

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 
+0

'routes.rb' 파일과'devise.rb' 파일을 게시 할 수 있습니까? –

+0

방금 ​​질문을 편집했습니다. 감사합니다. –

답변

0

귀하의 문제는 세션이다 : previous_url] 매장 fullpath에와 fullpath에 모든 것을 당신이 시도 의미 / 후 예를 들어 오류가 발생하는 이유와 fullpath가 전혀 존재하지 않기 때문에 다른 조건이 실행되지 않는다는 것을/사용자에게 리디렉션 할 수 있습니다.

[: previous_url] "#{request.protocol}#{request.host_with_port}#{request.fullpath}" 또는 request.original_url 세션에 저장하려고 시도하면 문제가 해결됩니다.

+0

도움을 주셔서 감사합니다. 세션 {: previous_url = request.fullpath}에 대한 세션 {: previous_url} = "# {request.protocol} # {request.host_with_port}"로의 세션 {: previous_url} 나는 이것을 시도하고 그것은 작동하지 않았다. –

관련 문제