Mohamed El Mahallawy
Mohamed El Mahallawy

Reputation: 13852

Rails caches_action to json content type

For some reason, render json: User.all with a caches_action for :index returns content type text/html. How do I force it to application/json?

Before:

def index
 render json: User.all.to_json
end

Returns json with Content-Type: 'application/json'

After:

caches_action :index

def index
 render json: User.all.to_json
end

Returns json with Content-Type: 'text/html'. So technically it's a json string in html.

Upvotes: 1

Views: 97

Answers (1)

joseramonc
joseramonc

Reputation: 1931

The safest way to do that, according to the documentation is to declare your route as a json route in your config/routes.rb

Upvotes: 1

Related Questions