gpt4 book ai didi

ruby-on-rails - POST 请求在 SSL 重定向后更改为 GET 请求

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:00 25 4
gpt4 key购买 nike

我想在我的 Rails 应用程序中以用户身份登录。没有 SSL 一切正常。当在暂存/生产中激活 SSL 时,有一个 SSL 重定向会在 GET 请求中更改我的 POST 请求。因此,在我的 session Controller 中调用 SHOW 方法而不是调用 CREATE 方法。这是日志:

Started POST "/authentication_customer_user_sessions" for *********** at 2014-07-30 10:42:30 +0200


Processing by Authentication::CustomerUserSessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authentication_customer_user_session"=>{"redirect_path"=>"user_index_path", "login"=>"user", "password"=>"[FILTERED]", "remember_me"=>"0"}, "account"=>{"signup"=>"with_signup"}, "commit"=>"signin"}
Redirected to https://staging.myserver.de/authentication_customer_user_sessions
Completed 302 Found in 5ms


Started GET "/authentication_customer_user_sessions" for *********** at 2014-07-30 10:42:30 +0200

AbstractController::ActionNotFound (The action 'show' could not be found for Authentication::CustomerUserSessionsController):

在我的 Authentication::CustomerUserSession-Controller 中我激活了 SSL

private  

def ssl_required?
return false if request.local? || RAILS_ENV == 'test' || RAILS_ENV == 'development'
true
end

那么在不为此 Controller 停用 SSL 的情况下,我可以在我的 Rails-App 中做什么来避免这个问题?感谢您的帮助!

我正在使用 authlogic 进行身份验证。

最佳答案

好的,我解决了我的问题。解决方案是在登录表单中强制使用 https。这是我的代码片段:

<%= form_for Authentication::CustomerUserSession.new, :as => :authentication_customer_user_session, :url => authentication_customer_user_sessions_url(:protocol => 'https') do |f| %>

或者更通用一点:

<%= form_for Authentication::CustomerUserSession.new, :as => :authentication_customer_user_session, :url => authentication_customer_user_sessions_url(:protocol => (Rails.env.production? || Rails.env.staging?) ? 'https' : 'http') do |f| %>

关于ruby-on-rails - POST 请求在 SSL 重定向后更改为 GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25032903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com