Created
December 3, 2012 03:17
-
-
Save sunny0425/4192427 to your computer and use it in GitHub Desktop.
set request default format (http://stackoverflow.com/questions/4643738/rails-3-respond-to-default-format)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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