1

在 Rails 3.0 应用程序中,我有一个控制器,其中包含许多类似这样的方法,

class ReviewsController
  # POST "/reviews/new_submit_form"
  def new_submit_for
    # some logic
    redirect_to new_subject_reviews_url(:format => "js")
  end
end

** terminal output **  

Started POST "/reviews/new_submit_form" for 127.0.0.1 at 2012-07-06 11:40:00 -0400
Processing by ReviewsController#new_submit_form as 
Parameters: {"question_sheet_id"=>"23"}
Existing local CAS session detected for "MYNAME@GMAIL.COM". Previous ticket "XX-1111-CjtSMaVpmiqBPsBoufke-plidma41" will be re-used.
Redirected to http://website.org/reviews/new_subject.js
Completed 302 Found in 1ms

问题是redirect_to new_subject_reviews_url(:format => "js")返回 HTTP url 而不是 HTTPS url。

我找到了一个解决方案, redirect_to new_subject_reviews_url(:format => "js", :protoco => "https://")但这需要我通过 Rails 应用程序编辑该方法。我怎样才能在我的 Rails 应用程序中全局修复这个问题,而无需主要破解 Rails?

4

1 回答 1

1

我没有找到原因,但我找到了解决方案。

Ccc360::Application.configure do

   # all the other configs

   # so that redirect_to will have, "https://www.mywebsite.org/xxxxxx"
  config.action_controller.default_url_options = { :protocol => "https" } 
end
于 2012-07-06T17:20:06.093 回答