Skip to content

Instantly share code, notes, and snippets.

@rociiu
Created October 12, 2010 00:50
Show Gist options
  • Save rociiu/621480 to your computer and use it in GitHub Desktop.
Save rociiu/621480 to your computer and use it in GitHub Desktop.
#http://refactormycode.com/codes/281-given-a-hash-of-variables-render-an-erb-template
require 'erb'
require 'ostruct'
def render_template(template, params)
vars = OpenStruct.new params
class << vars
include CustomHelper, ApplicationHelper, ActionView::Helpers::TextHelper
end
template = File.read("#{TEMPLATE_ROOT}/#{template_path}.html.erb")
puts ERB.new(template).result(vars.send(:binding))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment