0
我覆蓋after_sign_in_path_for
在我的ApplicationController
中。覆蓋設計after_sign_in_path_for給出錯誤:過濾器鏈暫停爲:require_no_authentication呈現或重定向
這裏的方法,使用Domainatrix解析的網址:
def after_sign_in_path_for(resource)
"#{resource.subdomain}." + host(request.url) + ":3000/profile"
end
def subdomain(url)
Domainatrix.parse(url).subdomain
end
def host(url)
Domainatrix.parse(url).host
end
當我點擊「提交」一旦我的日誌:
Started POST "https://stackoverflow.com/users/sign_in" for 127.0.0.1 at 2014-02-26 17:10:03 -0700
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"0aZ8da/kt+uxPDvzQj4ypyVDgTBW7FzRNR7uHN6Hryo=", "user"=>{"email"=>"EMAIL", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'EMAIL' LIMIT 1
(0.1ms) begin transaction
SQL (0.4ms) UPDATE "users" SET "last_sign_in_at" = ?, "current_sign_in_at" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = 16 [["last_sign_in_at", Thu, 27 Feb 2014 00:05:30 UTC +00:00], ["current_sign_in_at", Thu, 27 Feb 2014 00:10:03 UTC +00:00], ["sign_in_count", 65], ["updated_at", Thu, 27 Feb 2014 00:10:03 UTC +00:00]]
(1.3ms) commit transaction
Redirected to trevor.lvh.me:3000/profile
Completed 302 Found in 70ms (ActiveRecord: 2.0ms)
這表明它重定向到正確的URL,但沒有發生任何事。
如果我點擊「提交」第二次,沒有任何反應和下面的日誌生成(注意2日至最後一行):
Started POST "https://stackoverflow.com/users/sign_in" for 127.0.0.1 at 2014-02-26 17:10:08 -0700
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"0aZ8da/kt+uxPDvzQj4ypyVDgTBW7FzRNR7uHN6Hryo=", "user"=>{"email"=>"EMAIL", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 16 ORDER BY "users"."id" ASC LIMIT 1
Redirected to trevor.lvh.me:3000/profile
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.2ms)
爲了進一步增加神祕感,當我改變after_sign_in_path_for
到:
def after_sign_in_path_for(resource)
if resource.subdomain == subdomain(request.url)
"#{root_url}profile"
end
end
它正確地重定向到trevor.lvh.me:3000/profile
。
任何想法這個Filter chain halted as :require_no_authentication rendered or redirected
錯誤是什麼?
謝謝你,工作完美。 –
問題:如果我使force_ssl = true,這會自動重定向到https等效嗎? –
這裏我們對'http://'進行硬編碼,但是你可以檢查'force_ssl'的值並相應地設置協議。 –