aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_controller/layout.rb15
-rw-r--r--actionpack/test/controller/mime_responds_test.rb5
-rw-r--r--actionpack/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb1
3 files changed, 15 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb
index f12b3f9b80..9cd7d0e8cf 100644
--- a/actionpack/lib/action_controller/layout.rb
+++ b/actionpack/lib/action_controller/layout.rb
@@ -234,10 +234,9 @@ module ActionController #:nodoc:
protected
def render_with_a_layout(options = nil, &block) #:nodoc:
- if template_with_options = options.is_a?(Hash)
- response.template.template_format = options[:content_type].to_sym if options[:content_type]
- end
-
+ template_with_options = options.is_a?(Hash)
+ set_template_format(options)
+
if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options))
assert_existence_of_template_file(layout)
@@ -307,5 +306,13 @@ module ActionController #:nodoc:
self.class.send(:layout_directory_exists_cache)[File.dirname(template_path)]
end
end
+
+ def set_template_format(options)
+ if options.is_a?(Hash) && options[:content_type]
+ response.template.template_format = options[:content_type].to_sym
+ elsif params[:format]
+ response.template.template_format = Mime::Type.lookup(Mime::Type.lookup_by_extension(params[:format]).to_s).to_sym
+ end
+ end
end
end \ No newline at end of file
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 526b7792be..959cb7c2f4 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -116,7 +116,8 @@ class RespondToController < ActionController::Base
def iphone_with_html_response_type
Mime::Type.register_alias("text/html", :iphone)
-
+ request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
+
respond_to do |type|
type.html { @type = "Firefox" }
type.iphone { @type = "iPhone" }
@@ -399,7 +400,7 @@ class MimeControllerTest < Test::Unit::TestCase
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
+ assert_equal "<html>Hello iPhone future from iPhone!</html>", @response.body
end
def test_format_with_custom_response_type_and_request_headers
diff --git a/actionpack/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb b/actionpack/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb
new file mode 100644
index 0000000000..17888ac303
--- /dev/null
+++ b/actionpack/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb
@@ -0,0 +1 @@
+Hello iPhone future from <%= @type -%>! \ No newline at end of file