Skip to content

Instantly share code, notes, and snippets.

@sunny0425
Created December 3, 2012 03:17
Show Gist options
  • Save sunny0425/4192427 to your computer and use it in GitHub Desktop.
Save sunny0425/4192427 to your computer and use it in GitHub Desktop.
# first scheme
before_filter :default_format_xml
# Set format to xml unless client requires a specific format
# Works on Rails 3.0.9
def default_format_xml
request.format = "xml" unless params[:format]
end
# second scheme
before_filter :default_format_json
def default_format_json
if(request.headers["HTTP_ACCEPT"].nil? &&
params[:format].nil?)
request.format = "json"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment