Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Missing :js template falls back to :html, so you don't have to explic…

…itly specify template format everywhere, breaking old code

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9119 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 6efee90bf234328e3672bc79408c2da5b9673539 1 parent 6b5fe9c
@jeremy jeremy authored
View
13 actionpack/lib/action_view/template_finder.rb
@@ -131,15 +131,20 @@ def extract_base_path_from(full_path)
# # => "rhtml"
#
def pick_template_extension(template_path)
- find_template_extension_from_handler(template_path) || find_template_extension_from_first_render
+ if extension = find_template_extension_from_handler(template_path, @template.template_format) || find_template_extension_from_first_render
+ extension
+ elsif @template.template_format == :js && extension = find_template_extension_from_handler(template_path, :html)
+ @template.template_format = :html
+ extension
+ end
end
- def find_template_extension_from_handler(template_path)
- formatted_template_path = "#{template_path}.#{@template.template_format}"
+ def find_template_extension_from_handler(template_path, template_format = @template.template_format)
+ formatted_template_path = "#{template_path}.#{template_format}"
view_paths.each do |path|
if (extensions = @@file_extension_cache[path][formatted_template_path]).any?
- return "#{@template.template_format}.#{extensions.first}"
+ return "#{template_format}.#{extensions.first}"
elsif (extensions = @@file_extension_cache[path][template_path]).any?
return extensions.first.to_s
end
View
28 actionpack/test/template/template_object_test.rb
@@ -59,4 +59,32 @@ def test_should_prepare_on_initialization
end
end
+ class PartialTemplateFallbackTest < Test::Unit::TestCase
+ def setup
+ @view = ActionView::Base.new(LOAD_PATH_ROOT)
+ @path = 'test/layout_for_partial'
+ end
+
+ def test_default
+ template = ActionView::PartialTemplate.new(@view, @path, nil)
+ assert_equal 'test/_layout_for_partial', template.path
+ assert_equal 'erb', template.extension
+ assert_equal :html, @view.template_format
+ end
+
+ def test_js
+ @view.template_format = :js
+ template = ActionView::PartialTemplate.new(@view, @path, nil)
+ assert_equal 'test/_layout_for_partial', template.path
+ assert_equal 'erb', template.extension
+ assert_equal :html, @view.template_format
+ end
+
+ def test_xml
+ @view.template_format = :xml
+ assert_raise ActionView::ActionViewError do
+ ActionView::PartialTemplate.new(@view, @path, nil)
+ end
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.