diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-15 04:18:32 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-15 04:18:32 +0000 |
commit | d48039cefb684d678480e1f078c6082792038d03 (patch) | |
tree | e10145a291c4424e69e7e8e0ed4aeaacd067c4ec /actionpack/lib/action_controller | |
parent | c87206cc575031ae5d422a7729e32954e1184b26 (diff) | |
download | rails-d48039cefb684d678480e1f078c6082792038d03.tar.gz rails-d48039cefb684d678480e1f078c6082792038d03.tar.bz2 rails-d48039cefb684d678480e1f078c6082792038d03.zip |
Fixed that setting request.format would also affect respond_to blocks [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7479 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller')
-rwxr-xr-x | actionpack/lib/action_controller/request.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index ceedcfec4f..0f14ede347 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -12,9 +12,6 @@ module ActionController # such as { 'RAILS_ENV' => 'production' }. attr_reader :env - # The requested content type, such as :html or :xml. - attr_writer :format - # The HTTP request method as a lowercase symbol, such as :get. # Note, HEAD is returned as :get since the two are functionally # equivalent from the application's perspective. @@ -90,6 +87,23 @@ module ActionController def format @format ||= parameters[:format] ? Mime::Type.lookup_by_extension(parameters[:format]) : accepts.first end + + + # Sets the format by string extension, which can be used to force custom formats that are not controlled by the extension. + # Example: + # + # class ApplicationController < ActionController::Base + # before_filter :adjust_format_for_iphone + # + # private + # def adjust_format_for_iphone + # request.format = :iphone if request.env["HTTP_USER_AGENT"][/iPhone/] + # end + # end + def format=(extension) + parameters[:format] = extension.to_s + format + end # Returns true if the request's "X-Requested-With" header contains # "XMLHttpRequest". (The Prototype Javascript library sends this header with |