mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
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.
This commit is contained in:
@@ -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.)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user