aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/layout.rb4
-rw-r--r--actionpack/test/controller/mime_responds_test.rb31
-rw-r--r--actionpack/test/fixtures/respond_to/iphone_with_html_response_type.html.erb1
4 files changed, 35 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index f8ac1237ea..cdd82db90a 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that default layouts did not take the format into account #9564 [lifofifo]
+
* Fixed optimized route segment escaping. #9562 [wildchild, Jeremy Kemper]
* root_path returns '/' not ''. #9563 [lifofifo]
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index 0c1513c9a1..f12b3f9b80 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -234,7 +234,9 @@ module ActionController #:nodoc:
protected
def render_with_a_layout(options = nil, &block) #:nodoc:
- template_with_options = options.is_a?(Hash)
+ if template_with_options = options.is_a?(Hash)
+ response.template.template_format = options[:content_type].to_sym if options[:content_type]
+ end
if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options))
assert_existence_of_template_file(layout)
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 144aff7d7c..d2c70ed477 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -112,6 +112,17 @@ class RespondToController < ActionController::Base
type.html
type.js
end
+ end
+
+ def iphone_with_html_response_type
+ Mime::Type.register("text/iphone", :iphone)
+
+ respond_to do |type|
+ type.html { @type = "Firefox" }
+ type.iphone { @type = "iPhone"; render :content_type => Mime::HTML }
+ end
+
+ Mime.send :remove_const, :IPHONE
end
def rescue_action(e)
@@ -120,7 +131,7 @@ class RespondToController < ActionController::Base
protected
def set_layout
- if action_name == "all_types_with_layout"
+ if ["all_types_with_layout", "iphone_with_html_response_type"].include?(action_name)
"standard"
end
end
@@ -380,5 +391,21 @@ class MimeControllerTest < Test::Unit::TestCase
get :using_defaults, :format => "xml"
assert_equal "using_defaults - xml", @response.body
- end
+ end
+
+ def test_format_with_custom_response_type
+ get :iphone_with_html_response_type
+ assert_equal "<html>Hello future from Firefox!</html>", @response.body
+
+ get :iphone_with_html_response_type, :format => "iphone"
+ assert_equal "text/html", @response.content_type
+ assert_equal "<html>Hello future from iPhone!</html>", @response.body
+ end
+
+ def test_format_with_custom_response_type_and_request_headers
+ @request.env["HTTP_ACCEPT"] = "text/iphone"
+ get :iphone_with_html_response_type
+ assert_equal "<html>Hello future from iPhone!</html>", @response.body
+ assert_equal "text/html", @response.content_type
+ end
end
diff --git a/actionpack/test/fixtures/respond_to/iphone_with_html_response_type.html.erb b/actionpack/test/fixtures/respond_to/iphone_with_html_response_type.html.erb
new file mode 100644
index 0000000000..1f3f1c6516
--- /dev/null
+++ b/actionpack/test/fixtures/respond_to/iphone_with_html_response_type.html.erb
@@ -0,0 +1 @@
+Hello future from <%= @type -%>! \ No newline at end of file