Created
March 16, 2012 08:54
-
-
Save jamesmoriarty/2049208 to your computer and use it in GitHub Desktop.
render erb template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.9.2p290 :013 > render_erb("Hey, <%= first_name %> <%= last_name %>", :first_name => "James", :last_name => "Moriarty") | |
=> "Hey, James Moriarty" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
require 'ostruct' | |
def render_erb(template, locals) | |
ERB.new(template).result(OpenStruct.new(locals).instance_eval{ binding }) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment