Fix partial rendering with dot in filename
When rendering a collection with a partial whose filename contains a dot, e.g. "customer.mobile", we would set a `locals[:'customer.mobile']` variable instead of, as in earlier versions of Rails, `locals[:customer]`. This bug was introduced in da9038eaa5d19c77c734a044c6b35d7bfac01104.
This commit is contained in:
parent
25c7c4adc9
commit
39c44480a2
@ -521,7 +521,7 @@ def retrieve_template_keys
|
||||
def retrieve_variable(path, as)
|
||||
variable = as || begin
|
||||
base = path[-1] == "/".freeze ? "".freeze : File.basename(path)
|
||||
raise_invalid_identifier(path) unless base =~ /\A_?(.*)(?:\.\w+)*\z/
|
||||
raise_invalid_identifier(path) unless base =~ /\A_?(.*?)(\.\w+)*\z/
|
||||
$1.to_sym
|
||||
end
|
||||
if @collection
|
||||
|
1
actionview/test/fixtures/test/_customer.mobile.erb
vendored
Normal file
1
actionview/test/fixtures/test/_customer.mobile.erb
vendored
Normal file
@ -0,0 +1 @@
|
||||
Hello: <%= customer.name rescue "Anonymous" %>
|
@ -270,6 +270,11 @@ def test_render_partial_collection
|
||||
assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
|
||||
end
|
||||
|
||||
def test_render_partial_collection_with_partial_name_containing_dot
|
||||
assert_equal "Hello: davidHello: mary",
|
||||
@view.render(:partial => "test/customer.mobile", :collection => [ Customer.new("david"), Customer.new("mary") ])
|
||||
end
|
||||
|
||||
def test_render_partial_collection_as_by_string
|
||||
assert_equal "david david davidmary mary mary",
|
||||
@view.render(:partial => "test/customer_with_var", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => 'customer')
|
||||
|
Loading…
Reference in New Issue
Block a user