Created
September 27, 2012 20:37
-
-
Save brunobord/3796330 to your computer and use it in GitHub Desktop.
ERB not working
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' | |
weekday = Time.now.strftime('%A') | |
simple_template = "Today is <%= weekday %>." | |
renderer = ERB.new(simple_template) | |
puts output = renderer.result() | |
# This throws: | |
# NameError: undefined local variable or method `weekday' for #<Object:0x10116b2a8> | |
# from (erb):1 | |
### Solution: | |
puts output = renderer.result(binding) | |
# this magically binds globals and pass them to the template. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment