Rails 应用程序的 HTTPS - InvalidAuthenticityToken [英] HTTPS for Rails Application - InvalidAuthenticityToken

查看:43
本文介绍了Rails 应用程序的 HTTPS - InvalidAuthenticityToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 https 为我的 Rails 应用程序工作.当我尝试在应用程序上执行任何与帖子相关的活动时,我收到以下错误.

I am trying to get https to work for my rails application. When i try to do any post related activity on the application i am getting the following error.

Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/actionpack-5.0.4/lib/action_controller/metal/request_forgery_protection.rb:195 - ActionCon
troller::InvalidAuthenticityToken
Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/actionpack-5.0.4/lib/action_controller/metal/rescue.rb:23 - ActionController::InvalidAuthe
nticityToken
Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.0.4/lib/active_support/notifications/instrumenter.rb:25 - ActionController
::InvalidAuthenticityToken
Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/actionpack-5.0.4/lib/action_dispatch/middleware/callbacks.rb:42 - ActionController::Invali
dAuthenticityToken
Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/actionpack-5.0.4/lib/action_dispatch/middleware/debug_exceptions.rb:77 - ActionController:
:InvalidAuthenticityToken

推荐答案

尝试将其添加到您的 config/environments/production.rb:

Try adding this to your config/environments/production.rb:

# config/environments/production.rb
Rails.application.configure do
  config.force_ssl = true
end

如果你想让它在其他环境中生效,把它添加到适当的环境文件.

If you want this to take effect in the other environments, add it to the appropriate environment file as well.

这篇关于Rails 应用程序的 HTTPS - InvalidAuthenticityToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆