1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed that default layouts did not take the format into account #9564 [lifofifo]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7514 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2007-09-18 23:10:34 +00:00
parent 2f60bb3327
commit 0d99423727
4 changed files with 35 additions and 3 deletions

View file

@ -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]

View file

@ -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)

View file

@ -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

View file

@ -0,0 +1 @@
Hello future from <%= @type -%>!