ROR return JSON with 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.