Heroku的。 Cookie有效,但不是会话

时间:2017-04-10 05:46:03

标签: ruby-on-rails ruby heroku cookies session-cookies

有人可以解释为什么Cookie适用于Heroku但不适用于会话。

以下方法将输出一个数字,每次刷新页面时都会增加该数字。这两个示例都适用于我的本地环境,但在Heroku上有所不同。

会话 Heroku

def test
  if !session[:x]
    session[:x] = 0
  end
  session[:x] = session[:x].to_i + 1
  render plain: session[:x].to_s
end

Cookie 确实 Heroku 上工作

def test
  if !cookies[:x]
    cookies[:x] = 0
  end
  cookies[:x] = cookies[:x].to_i + 1
  render plain: cookies[:x].to_s
end

为什么不开会?

我需要会议才能工作,我对任何想法感到高兴。我是rails和Heroku的新手,所以我可能会遗漏一些非常基本的东西。我是否需要在rails或Heroku中进行设置?

我的设置......

production.rb

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.public_file_server.enabled = true
  config.assets.js_compressor = :uglifier
  config.assets.compile = false
  config.assets.digest = true
  config.log_level = :debug
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  config.active_record.dump_schema_after_migration = false
  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end
end

development.rb

Rails.application.configure do
  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false
  config.action_mailer.raise_delivery_errors = false
  config.active_support.deprecation = :log
  config.active_record.migration_error = :page_load
  config.assets.debug = true
  config.assets.digest = true
  config.assets.raise_runtime_errors = true
end

配置/初始化/ session_store.rb

Rails.application.config.session_store :cookie_store, key: '_your_app_session', domain: :all

0 个答案:

没有答案