【发布时间】:2014-09-18 11:06:32
【问题描述】:
所以我有一个 Rails 应用程序,它在 Heroku 上有一个暂存环境和一个生产环境。我想在生产环境中强制使用 ssl,而不是在暂存环境中强制使用 ssl。我的应用程序控制器(如下)显示了我的配置方式,但我的暂存环境仍在尝试强制 ssl 工作,这导致了重定向循环。
我的问题是:A) 我如何停止重定向循环并让应用程序不会因强制使用 ssl 而崩溃?和 B) 我必须做什么才能阻止 force_ssl 在我尚未完成的暂存环境中发生?
谢谢!
class ApplicationController < ActionController::Base
force_ssl if: :ssl_configured?
before_action :configure_permitted_parameters, if: :devise_controller?
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
# Make application helpers availble within controllers
include ApplicationHelper
# enable_authorization :unless => :devise_controller? # ACl
before_filter do # ACL work around for attribute mass assignment
resource = controller_path.singularize.gsub('/', '_').to_sym
method = "#{resource}_params"
params[resource] &&= send(method) if respond_to?(method, true)
end
rescue_from CanCan::Unauthorized do |exception|
redirect_to main_app.root_path, :alert => exception.message
end
#handling redirection after login basing on the just logged in user role
def after_sign_in_path_for(user)
if user.has_role?(:director)
unless user.organization.nil?
dashboard_organization_path(user.organization.id)
else
organization_trainings_url
end
elsif user.has_role?(:user)
user_path(user)
elsif user.has_role?(:admin)
organization_trainings_url
else
root_url
end
end
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << [:first_name, :last_name, :title, :phone, :email,
:organization_id, :badge, :dl,
:hire_date, :dl_expiration, :leader_id, :password, :current_password,
:division_id, :bureau_id]
end
private
def ssl_configured?
Rails.env.production?
end
end
【问题讨论】:
-
你检查过
staging是否真的是staging吗?Rails.env.production?在您的 heroku 控制台中返回什么? -
false 是我输入时得到的结果
-
还有
Rails.env.staging?? -
你解决了吗?我也有同样的问题。
-
这里也一样。有什么见解吗?
标签: ruby-on-rails ruby ssl heroku ruby-on-rails-4