Skip to content

Instantly share code, notes, and snippets.

@nirix
Created December 11, 2011 07:45
Show Gist options
  • Save nirix/1459168 to your computer and use it in GitHub Desktop.
Save nirix/1459168 to your computer and use it in GitHub Desktop.
Partials in Sinatra
#
# Sinatra Partials
# Copyright (C) 2011 Jack Polgar
#
# @copyright Jack Polgar 2011
# @license New BSD License
# @example:
# render_partial 'articles/article', :article => article
#
helpers do
def render_partial(template, args = {})
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
erb(template.to_sym, :locals => args, :layout => false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment