作爲認證用戶,如果我通過外部文本編輯器訪問我的應用程序的網址,mimetype在控制檯顯示爲「*/*」,並且設計好像多次重定向到「/ sign_in」。這是一個問題,因爲如果我轉到「/ foo」,它最初會存儲在會話中作爲身份驗證後返回的路徑。由於重定向的次數,這個值在會話中被吹走了,在設計終於意識到用戶已經登錄後,它最終重定向到「/」。設計變得瘋狂與接受標題的「*/*」
爲了測試,我加入到我的應用程序控制器:
def authenticate_user!
puts "***** AUTHENTICATE USER CALLED!!!"
super
end
所以,如果我直接在瀏覽器中輸入網址,將MIME類型顯示爲HTML,它看到我馬上驗證,一切都呈現爲預期:
Started GET "/products/171" for 127.0.0.1 at 2015-02-11 17:04:53 -0800
ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by LayoutsController#show as HTML
Parameters: {"id"=>"171"}
***** AUTHENTICATE USER CALLED!!!
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = 7 ORDER BY "users"."id" ASC LIMIT 1
Rendered html template within layouts/application (0.1ms)
Completed 200 OK in 1165ms (Views: 1127.7ms | ActiveRecord: 3.0ms)
然而,當我點擊外部文本編輯器的鏈接,我得到這個瘋狂的行爲:
Started GET "/products/171" for 127.0.0.1 at 2015-02-11 17:09:43 -0800
Processing by LayoutsController#show as */*
Parameters: {"id"=>"171"}
***** AUTHENTICATE USER!!!
Completed 401 Unauthorized in 4ms
I18N keys: [:en, :devise, :failure, :user, :unauthenticated]
I18N keys: [:en, :devise, :failure, :unauthenticated]
=> You need to sign in or sign up before continuing.
Started GET "/sign_in" for 127.0.0.1 at 2015-02-11 17:09:43 -0800
Processing by Devise::SessionsController#new as */*
I18N keys: [:en, :sign_in, :submit_button]
=> Sign in
I18N keys: [:en, :sign_in, :disabled]
=> Your account has been disabled.
Rendered devise/sessions/new.html.haml within layouts/sign_in (6.8ms)
Started GET "/sign_in" for 127.0.0.1 at 2015-02-11 17:09:45 -0800
Processing by Devise::SessionsController#new as HTML
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 7 ORDER BY "users"."id" ASC LIMIT 1
I18N keys: [:en, :devise, :failure, :already_authenticated]
=> You are already signed in.
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 5ms (ActiveRecord: 0.5ms)
Started GET "/" for 127.0.0.1 at 2015-02-11 17:09:45 -0800
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 7 ORDER BY "users"."id" ASC LIMIT 1
Processing by LayoutsController#show as HTML
***** AUTHENTICATE USER!!!
Completed 200 OK in 244ms (Views: 178.8ms | ActiveRecord: 0.0ms)
請注意「重定向到http://localhost:3000/」而不是http://localhost:3000/products/171,這是應該發生的事情。
*/*爲什麼導致這種行爲,我該如何解決這個問題?
UPDATE
顯然的問題是,我得到直接從Chrome的地址欄訪問之間的完全不同的會話,並從單擊外部文本編輯器(鏈接即使文本編輯器簡單地打開Chrome新標籤與URL):
從鉻單擊外部文本編輯器鏈接後:從把URL直接在Chrome
request.cookies => {"_my_app_session"=>"f32dc5c239fadfc494a775990112f2b5"}
:
request.cookies => {"_my_app_session"=>"91ac136666b78499ea6e071f89cec7ee"}
這是怎麼可能的呢?這是相同的瀏覽器..我認爲瀏覽器中的所有標籤都具有相同的會話,並且您無法更改該標籤?