--I'm using Rails in API mode ([English version] of the ← document (https://guides.rubyonrails.org/api_app.html)).
Or
--ʻActionController :: API` is inherited and the controller for API is used.
As it is, cookies cannot be accessed, so we will make it accessible.
Here, the latter is assumed (the controller for API is used by inheriting ʻActionController :: API`).
ʻInclude ActionController :: Cookies on the base controller that inherits ʻActionController :: API
, or on the controller that you actually want to access cookies
.
In other words
class YourApiBaseController < ActionController::API
include ActionController::Cookies
Or
class YourApiController < YourApiBaseController
include ActionController::Cookies
config/application.rb
module YourApi
class Application < Rails::Application
config.middleware.use ActionDispatch::Cookies
It is necessary to set session_store
and credentials.yml.enc
(secrets.yml *
in the case of the old version) separately.
config/initializers/session_store.rb
Rails.application.config.session_store :cookie_store, key: 'your-cookie-key-comes-here'
Recommended Posts