aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-06-27 21:24:21 +0300
committerMichael Koziarski <michael@koziarski.com>2008-07-03 19:43:06 +0300
commit12cf8f348b591b7bb0dc899345293a8e37ddad7c (patch)
treedeed5125fe33f677413b15d242431b32ae39b156
parentdc2d754d60378b529c239e1291932503d4d8fca5 (diff)
downloadrails-12cf8f348b591b7bb0dc899345293a8e37ddad7c.tar.gz
rails-12cf8f348b591b7bb0dc899345293a8e37ddad7c.tar.bz2
rails-12cf8f348b591b7bb0dc899345293a8e37ddad7c.zip
Move template_format logic out to the request so it's alongside the 'regular' request format.
Use xhr? instead of the expensive trip through Request#accepts.
-rwxr-xr-xactionpack/lib/action_controller/request.rb13
-rw-r--r--actionpack/lib/action_view/base.rb12
-rw-r--r--actionpack/test/controller/new_render_test.rb3
3 files changed, 15 insertions, 13 deletions
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb
index 9b02f2c8a1..c91a3387a0 100755
--- a/actionpack/lib/action_controller/request.rb
+++ b/actionpack/lib/action_controller/request.rb
@@ -116,6 +116,19 @@ module ActionController
@format = Mime::Type.lookup_by_extension(parameters[:format])
end
+ def template_format
+ parameter_format = parameters[:format]
+
+ case
+ when parameter_format.blank? && !xhr?
+ :html
+ when parameter_format.blank? && xhr?
+ :js
+ else
+ parameter_format.to_sym
+ end
+ end
+
# Returns true if the request's "X-Requested-With" header contains
# "XMLHttpRequest". (The Prototype Javascript library sends this header with
# every Ajax request.)
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 9e255bd324..e8e690abec 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -273,17 +273,7 @@ module ActionView #:nodoc:
return @template_format if @template_format
if controller && controller.respond_to?(:request)
- parameter_format = controller.request.parameters[:format]
- accept_format = controller.request.accepts.first
-
- case
- when parameter_format.blank? && accept_format != :js
- @template_format = :html
- when parameter_format.blank? && accept_format == :js
- @template_format = :js
- else
- @template_format = parameter_format.to_sym
- end
+ @template_format = controller.request.template_format
else
@template_format = :html
end
diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb
index d60bacd52a..b2691d981b 100644
--- a/actionpack/test/controller/new_render_test.rb
+++ b/actionpack/test/controller/new_render_test.rb
@@ -605,8 +605,7 @@ EOS
end
def test_render_with_default_from_accept_header
- @request.env["HTTP_ACCEPT"] = "text/javascript"
- get :greeting
+ xhr :get, :greeting
assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body
end