Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPS for Rails Application - InvalidAuthenticityToken

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
like image 575
Harsha M V Avatar asked Oct 17 '17 15:10

Harsha M V


1 Answers

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.

like image 181
Tom Aranda Avatar answered Oct 25 '22 23:10

Tom Aranda