我认为我的会话等都搞砸了,因为我最近添加了代码以确保正确的协议(某些页面上的 https,而其他页面上的 http)。不过我不确定。Filter chain halted as :ensure_proper_protocol rendered or redirected
但我一直在我的日志中看到。
`:ensure_proper_protocol 方法是指我在应用程序控制器中拥有的方法:
class ApplicationController < ActionController::Base
CONTROLLERS_THAT_REQUIRE_SSL = ['check_out', 'users', 'sessions', 'registrations', 'addresses', 'catalog_requests', 'wine_club/orders']
def ensure_proper_protocol
unless Rails.env.development? || Rails.env.test?
if request.format == "text/html" && request.protocol["https"] && !CONTROLLERS_THAT_REQUIRE_SSL.include?(params[:controller])
redirect_to "http://" + request.host + request.path
end
end
end
对于 CONTROLLES_THAT_REQUIRE_SSL 中的控制器,我添加force_ssl
如下:
class CheckOutController < ApplicationController
force_ssl
...
但是,我想知道协议中的切换是否会搞砸我的会话。我的会话问题和这个错误有关吗?如何修复“过滤器链停止”错误?
我遇到的会话问题与设计和身份验证有关。我有一个前置过滤器:authenticate_user!虽然我设法登录,但它似乎并没有保持登录状态。问题是没有错误消息。它只是出于某种原因注销,我很确定这是因为重定向,因为我的应用程序控制器中有一个 before 过滤器来查看用户是否已登录,并且它使用 devise helper 方法user_signed_in?
来查看是否用户已登录。看看我的日志:
Cache read: https://mysite-rc-preview.mysite.com/users/sign_in?
Started POST "/users/sign_in" for 69.193.194.58 at 2013-09-04 12:09:38 -0400
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"bSYhk5t7VPBUTGkQuVyix8cb7Et7yojPE5m0V/g+do8=", "user"=>{"email"=>"emai@mysite.com", "password"=>"[FILTERED]"}, "commit"=>"Log in"}
inside setup_cart. current_cart_id is 55005260
55005260
request.session_options[:id] = eecb979b4d7db5bfd28a3684ef7288d3
User Load (2.9ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'emai@mysite.com' LIMIT 1
(1.9ms) BEGIN
(2.2ms) UPDATE "users" SET "last_sign_in_at" = '2013-09-04 16:07:44.987529', "current_sign_in_at" = '2013-09-04 16:09:39.171144', "sign_in_count" = 34, "updated_at" = '2013-09-04 16:09:39.174358' WHERE "users"."id" = 350492
(10.6ms) COMMIT
begining get_or_create_cart session[:current_cart_id] is 55005260
Cart Load (2.3ms) SELECT "carts".* FROM "carts" WHERE "carts"."user_id" = 350492 AND "carts"."id" = 55005260 LIMIT 1
Cart Load (2.2ms) SELECT "carts".* FROM "carts" WHERE "carts"."user_id" = 350492
end of get_or_create_cart session[:current_cart_id] is 54993421
SeoContent Load (2.2ms) SELECT "seo_contents".* FROM "seo_contents" WHERE "seo_contents"."for_section" = 'default' LIMIT 1
There's no session[:cvv] variable
Cart Load (2.2ms) SELECT "carts".* FROM "carts" WHERE "carts"."web_cart_session" = 'eecb979b4d7db5bfd28a3684ef7288d3'
Cart Load (2.4ms) SELECT "carts".* FROM "carts" WHERE "carts"."user_id" = 350492 AND "carts"."name" = 'My Cart' LIMIT 1
CartItem Load (2.2ms) SELECT "cart_items".* FROM "cart_items" WHERE "cart_items"."cart_id" = 55005260 ORDER BY created_at
(1.9ms) BEGIN
SQL (2.4ms) DELETE FROM "carts" WHERE "carts"."id" = $1 [["id", 55005260]]
(6.5ms) COMMIT
Redirected to https://mysite-rc-preview.mysite.com/
Completed 302 Found in 408ms (ActiveRecord: 42.0ms)
Cache read: https://mysite-rc-preview.mysite.com/?
Started GET "/" for 69.193.194.58 at 2013-09-04 12:09:39 -0400
Processing by SiteController#index as HTML
Redirected to http://mysite-rc-preview.mysite.com/
Filter chain halted as :ensure_proper_protocol rendered or redirected
Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
Cache read: http://mysite-rc-preview.mysite.com/?
Started GET "/" for 69.193.194.58 at 2013-09-04 12:09:39 -0400
Processing by SiteController#index as HTML
inside setup_cart. current_cart_id is 54993421
54993421
request.session_options[:id] = 4bec2bbc42e8213be89aaf6431b41535
inside not user_signed_in? clause of setup_cart
登录后它会将我重定向到主页,这没关系,但之后它会从 http:// ... / 重定向到 https:// ... / ,这导致用户不再登录。这可能是因为我的会话没有像我配置的那样存储在数据库中吗?我的 config/initializers/session_store.rb 中确实有这一行:
mysite::Application.config.session_store :active_record_store