I want to respond with json to all formats.
I can force the render format to json
so the action will render show.json
despite the accept
header:
def show
render formats: :json
end
How I can set render format for all actions of the controller?
Something like this:
class GalleriesController < ApplicationController
formats :json
end
As a summary of all comments to the questions and readability for future users, you can do, as mentioned here:
before_filter :default_format_json
def default_format_json
request.format = "json"
end
In your controller:
def my_action
formats.clear
formats << :json
end
(I've only tested this in Rails 4.2 and 3.2.)
formats
returns an Array of format symbols. It is delegated to @_lookup_context
, which is an instance of ActionView::LookupContext
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With