Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save timriley/282437 to your computer and use it in GitHub Desktop.
Save timriley/282437 to your computer and use it in GitHub Desktop.
not_found do
render_template_if_exists!
end
def render_template_if_exists!
name = File.basename(request.path)
Dir["#{Sinatra::Application.root}/views/#{name}.*"].each do |match|
@_format = File.extname(match).sub(/^./, '')
@_template = File.basename(match, File.extname(match))
end
eval("#{@_format} :#{@_template}") if @_format and @_template
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment