Answer the question
In order to leave comments, you need to log in
How to add a cookie to the response?
Hello. Can you please tell me how to make the response have cookies?
The settings are config.api_only = true
here is an example
def test_cookie
cookies[:cookie_name1] = 'cookie_value1'
cookies[:cookie_name22] = 'cookie_value22'
render json: { status: true }
end
class ApplicationController < ActionController::API
include ActionController::Cookies
end
module RailsApiDemo
class Application < Rails::Application
config.load_defaults 5.1
config.api_only = true
end
end
Answer the question
In order to leave comments, you need to log in
# config/application.rb
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore, key: '_coookie_name', expire_after: 30.days
No way. Middleware for sessions and cookies is disabled in API mode.
Why are there cookies in the API? Something is wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question