Skip to content

Instantly share code, notes, and snippets.

@brunobord
Created September 27, 2012 20:37
Show Gist options
  • Save brunobord/3796330 to your computer and use it in GitHub Desktop.
Save brunobord/3796330 to your computer and use it in GitHub Desktop.
ERB not working
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