When we return JSON output using render :json =>@profiles
, the
output will return the required results with a 406 error. How can
avoid that '406 Not Acceptable' error ?
I'm more than sure that you have this problem.
Explanations:
Say your controller only returns json answers
def action
# call
respond_to do |format|
format.json { render json: results }
end
end
This will return the json as soon as:
/path_to_action.json
is called/path_to_action
is called with headers Content-Type:application/json;
and probably some other header types (Eg. X-Requested-With:XMLHttpRequest
)Otherwise, it returns a 406 Not Acceptable
error.
To avoid the issue, if your controller only returns json, write:
def action
# call
render json: results
end
otherwise, use /path_to_action.json
instead.
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