Skip to content

Instantly share code, notes, and snippets.

@rwilcox
Created May 12, 2011 21:19
Show Gist options
  • Select an option

  • Save rwilcox/969472 to your computer and use it in GitHub Desktop.

Select an option

Save rwilcox/969472 to your computer and use it in GitHub Desktop.
default_html_template_format.rb
# Create our own FileSystemResolver so that it looks for a .html file to render if
# the (action).(format).erb file is not there. Useful for our MIME alias format.partial -
# instead of needing to create a (something).partial.erb file we can use (something).html.erb
# and use the template for both
#
# In this case (something).partial.erb files will be used if we want to provide something different than
# what the normal partial provides us. WD-rpw 05-12-2011
class DefaultHtmlTemplateFormat < ActionView::FileSystemResolver
def initialize path
super(path)
end
def find_templates(name, prefix, partial, details)
templates = super(name, prefix, partial, details)
return templates if templates.present?
unless details[:formats] == [:html]
new_details = details.dup
new_details[:formats] = [:html]
templates = super(name, prefix, partial, new_details)
end
return templates
end
end
ActiveSupport.on_load(:action_controller) do
view_paths.each do |path|
append_view_path(DefaultHtmlTemplateFormat.new(path.to_s))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment