我在after_sign_in_path_for
覆盖ApplicationController
。
这是方法,使用Domainatrix解析URL:
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 "/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 "/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
错误是什么?
答案 0 :(得分:2)
替换
def after_sign_in_path_for(resource)
"#{resource.subdomain}." + host(request.url) + ":3000/profile"
end
使用
def after_sign_in_path_for(resource)
"http://#{resource.subdomain}." + host(request.url) + ":3000/profile"
end
http://
协议遗失。