diff options
author | Yehuda Katz <wycats@gmail.com> | 2008-12-25 17:12:33 -0800 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2008-12-25 17:12:33 -0800 |
commit | 69e349f1bb31c80215775956467fd54e00a2f0fe (patch) | |
tree | 5c1cd0d3e20e7c8f4e07e2ee5e62949a1a5fce22 /actionpack/lib/action_controller/request.rb | |
parent | 061952392afd1dae1aa97a816e9a0c79df7c4514 (diff) | |
download | rails-69e349f1bb31c80215775956467fd54e00a2f0fe.tar.gz rails-69e349f1bb31c80215775956467fd54e00a2f0fe.tar.bz2 rails-69e349f1bb31c80215775956467fd54e00a2f0fe.zip |
Initial work to merge several places with similar logic
Diffstat (limited to 'actionpack/lib/action_controller/request.rb')
-rwxr-xr-x | actionpack/lib/action_controller/request.rb | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 8a02130d88..f62567af41 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -152,24 +152,33 @@ module ActionController end end + ONLY_ALL = [Mime::ALL].freeze + # Returns the Mime type for the \format used in the request. # # GET /posts/5.xml | request.format => Mime::XML # GET /posts/5.xhtml | request.format => Mime::HTML # GET /posts/5 | request.format => Mime::HTML or MIME::JS, or request.accepts.first depending on the value of <tt>ActionController::Base.use_accept_header</tt> + def format @format ||= if parameters[:format] - Mime::Type.lookup_by_extension(parameters[:format]) - elsif ActionController::Base.use_accept_header - accepts.first - elsif xhr? - Mime::Type.lookup_by_extension("js") - else - Mime::Type.lookup_by_extension("html") + Mime[parameters[:format]] + elsif Base.use_accept_header && !(accepts == ONLY_ALL) + accepts.first + elsif xhr? then Mime::JS + else Mime::HTML end end + def formats + @formats = + if Base.use_accept_header + Array(Mime[parameters[:format]] || accepts) + else + [format] + end + end # Sets the \format by string extension, which can be used to force custom formats # that are not controlled by the extension. |