Erb on the Herb?

L

Lyndon Samson

------=_Part_3645_22730402.1124349688656
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

There seems to be some issue with the binding in ERB, any ideas?

(erb):16: undefined local variable or method `priority' for main:Object=20
(NameError)
from d:/utils/ruby/lib/ruby/1.8/erb.rb:739:in `value'
from d:/utils/ruby/lib/ruby/1.8/erb.rb:739:in `result'
from testerb.rb:36

is what I get when I try to run the following, taken from=20
http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/=20

require "erb"

# Create template.
template =3D %q{
From: James Edward Gray II <[email protected]>
To: <%=3D to %>
Subject: Addressing Needs

<%=3D to[/\w+/] %>:

Just wanted to send a quick note assuring that your needs are being
addressed.

I want you to know that my team will keep working on the issues,
especially:

<%# ignore numerous minor requests -- focus on priorities %>
% priorities.each do |priority|
* <%=3D priority %>
% end

Thanks for your patience.

James Edward Gray II
}.gsub(/^ /, '')

message =3D ERB.new(template, 0, "%<>")

# Set up template data.
to =3D "Community Spokesman <spokesman@ruby_community.org>"
priorities =3D [ "Run Ruby Quiz",
"Document Modules",
"Answer Questions on Ruby Talk" ]

# Produce result.
email =3D message.result
puts email

------=_Part_3645_22730402.1124349688656--
 
S

Stephan Kämper

Lyndon said:
There seems to be some issue with the binding in ERB, any ideas?
I want you to know that my team will keep working on the issues,
especially:

<%# ignore numerous minor requests -- focus on priorities %>
% priorities.each do |priority|

This line -^ is just some other output of ERB - there are no '<%' ...
'%>' pairs...
* <%= priority %>
% end

Would this do it?

<% priorities.each do |priority| %>
* <%= priority %>
<% end %>


Hope that helped

Happy rubying

Stephan
 
D

Devin Mullins

Stephan said:
This line -^ is just some other output of ERB - there are no '<%' ...=20
'%>' pairs...

Not, according to the rdoc, when '%' is passed to ERB.new.

Devin
 
J

James Edward Gray II

There seems to be some issue with the binding in ERB, any ideas?

Works fine here. I pulled the code right out of your email and
pasted it into a file:

Neo:~/Desktop$ ruby erb_test.rb

From: James Edward Gray II <[email protected]>
To: Community Spokesman <spokesman@ruby_community.org>
Subject: Addressing Needs

Community:

Just wanted to send a quick note assuring that your needs are being
addressed.

I want you to know that my team will keep working on the issues,
especially:

* Run Ruby Quiz
* Document Modules
* Answer Questions on Ruby Talk

Thanks for your patience.

James Edward Gray II
Neo:~/Desktop$ ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin7.7.0]

I'm not sure what's going on.

James Edward Gray II
 
L

Lyndon Samson

------=_Part_5760_33077133.1124407785060
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
=20
=20
Works fine here. I pulled the code right out of your email and
pasted it into a file:



Hmm, it would be interesting if a few others could try it, it may be=20
something to do with my specific ruby environment.

D:\lcs\source\ruby>ruby -v
ruby 1.8.2 (2004-12-25) [i386-mswin32]

------=_Part_5760_33077133.1124407785060--
 
D

Devin Mullins

Lyndon said:
Works fine here. I pulled the code right out of your email and
pasted it into a file:
Hmm, it would be interesting if a few others could try it, it may be
something to do with my specific ruby environment.

D:\lcs\source\ruby>ruby -v
ruby 1.8.2 (2004-12-25) [i386-mswin32]
Works for me. Sorry!

C:\Documents and Settings\dlm>ruby -v
ruby 1.8.2 (2004-12-25) [i386-mswin32]

All I did was type "ruby", hit Enter, pasted in the code, hit Enter, hit
Ctrl-D, and hit Enter.

Devin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top