Update to my own post:
There are two paths depending on whether you have
config.action_view.cache_template_loading or not.
(Either EagerPath.load! or ReloadablePath.register_template)
EXAMPLE: Given the files:
views/main/index.html.erb
views/main/index.html.erb.backup
RESULT: get '/main' renders 'views/main/index.html.erb.backup'
PROBLEM:
In both cases (Eager, ReloadablePath) "@path[path]" is assigned twice,
setting "index.html.erb.backup" as the final template.
This is not relevant for production mode, since you don't usually have
backups of editor files there.
Backup files such as: "index.html.erb~" are handled correctly, BTW -
added to the list, but never used because of unique extension ("erb~").
QUESTION: Why does ActionView consider the *.backup files anyway?
ANSWER: They pass the ActionView::Template.split test:
elsif valid_extension?(m[1]) # format and extension
The thing is, index.html.erb.orig has 3 extensions m = ['html', 'erb',
'orig'] and m[2] is ignored. Idea: join m[1] and m[2] and return as
extension?
QUESTION: shouldn't both implementations(Eager/Reloadable) be identical,
except for handling _when_ to load the templates?
The differences may cause some problems to come up only in one case
(w/wo caching). E.g. my guess is that broken symbolic links will be
handled differently - ReloadablePath uses File.file?, which returns
false for the broken symlinks that the Dir.glob returns. EagerPath
doesn't seem to check that.
SOLUTION; Only assign a template once, don't clobber the previous value.
This works, because Dir.glob returns a sorted list, where
'index.html.erb' is at the top.
PATCH: The patch becomes trivial now:
--- template.rb.orig 2009-03-18 12:27:45.000000000 +0100
+++ template.rb 2009-03-20 12:15:14.698483807 +0100
@@ -64,7 +64,7 @@
templates_in_path do |template|
template.load!
template.accessible_paths.each do |path|
- @paths[path] = template
+ @paths[path] ||= template #don't clobber previous entry
with *.erb.backup files
end
end
@paths.freeze
--- reloadable_template.rb.orig 2009-03-18 12:27:45.000000000 +0100
+++ reloadable_template.rb 2009-03-20 13:13:43.866482672 +0100
@@ -41,7 +41,7 @@
def register_template(template)
template.accessible_paths.each do |path|
- @paths[path] = template
+ @paths[path] ||= template #don't clobber previous entry
with *.erb.backup files
end
end
Seems to work fine now. But does this solve/create other problems with
templates and caching?
Hope this helps and possibly prevents some headaches in the future.