Skip to content

Instantly share code, notes, and snippets.

@bwillis
Last active December 23, 2015 23:29
Show Gist options
  • Save bwillis/6710718 to your computer and use it in GitHub Desktop.
Save bwillis/6710718 to your computer and use it in GitHub Desktop.
Notes for version cake issue

Rails uses a concept called details to find a template using an Action View Resolver (actionpack-3.2.14/lib/action_view/template/resolver.rb). Version Cake registers an additional detail (called versions) to add more granularity when locating a template. The resolver builds a query from the details which is used to search the directory for the templates.

resolver = ActionView::OptimizedFileSystemResolver.new(Rails.root.join("app/views"))
template_name = "tester/index"
details = {:locale => [:en], :formats => [:html], :handlers => [:erb, :builder, :coffee, :jbuilder], :versions => [:v1]}

# without RABL
query = resolver.build_query(template_name, details)
 => ".../app/views/tester/index{.en,}{.v1,}{.html,}{.erb,.builder,.coffee,.jbuilder,}"
Dir[query]
 => [".../app/views/tester/index.html.erb"]

# with RABL
details[:handlers] << :rabl
query = resolver.build_query(template_name, details)
 => ".../app/views/tester/index{.en,}{.v1,}{.html,}{.erb,.builder,.coffee,.jbuilder,.rabl,}"
Dir[query]
 => [".../app/views/tester/index.v1.rabl", ".../app/views/tester/index.html.erb"]

Because of the additional version detail, the resolver believes the rabl template is a really good match, especially because of the version being ahead of the format.

I don't have a good solution yet, but a workaround could be to name the index.html.erb file to index.v1.html.erb so it is a better match than the RABL template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment