How to use Flash messages from a Rails API only controller

If you are debugging this Flash message error.

undefined local variable or method `flash' for

And you are currently using an API only Rails controller, but still want to use flash messages in your app because you are redirecting to a normal controller.

Then you can fix this by adding the following.

class CoolController < ActionController::API
  include ActionController::Flash
end

Good luck, hope this saved you some time.