0

I am using rails 6.0 in a new project and after that cookies are not set

 Include ActionDispatch::Cookies 
 Include ActionDispatch::Session::CookieStore 
  before_action :cookie_set
  def cookie_set
    cookies[:test] = {value: 'testset'}
  end

browser cookie is empty

Виктор
  • 47
  • 1
  • 5

1 Answers1

5

When you use your Rails application on api mode some middlewares that are needed to make cookies work are not included by default. To enable them maintaining api mode, edit your config/application.rb by adding:

# Stuff you application needs
class Application < Rails::Application
  config.middleware.use ActionDispatch::Cookies
  config.middleware.use ActionDispatch::Session::CookieStore, key: '_namespace_key'
# Maybe more stuff...
end
ErvalhouS
  • 4,178
  • 1
  • 22
  • 38