I have an application which uses a React component to update the user profile. With a backend of Rails, I'm attempting to pass a flash message on the #update
action which is connected to the Rails API that I built for the React frontend. ActionController::API
doesn't have the middleware of ActionController::Base
and I can't figure out where to include the ActionDispatch
middleware for the ActionController::API
.
I've tried adding it as a module (hoping that it may already be within the application):
Controller
class Api::V1::BaseController < ActionController::API
include ActionDispatch::Flash
I've also tried including the middleware into the config/application.rb
config/application.rb
module Subs
class Application < Rails::Application
config.generators do |generate|
generate.assets false
generate.helper false
generate.test_framework :test_unit, fixture: false
end
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
config.middleware.use ActionDispatch::Flash
end
end
I imagine that adding it to a general config/application.rb
is redundant as the ActionDispatch::Flash
is already included in the application.
Where could I add a middleware specifically for the ActionController::API
? Or how could I give it access to the ActionDispatch::Flash
that is already present in the ActionController::Base
?