Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use erb Template in ruby code
    primarykey
    data
    text
    <p>I want to use the <code>erb</code> template feature of ruby. But I am not able to run the sample code provided.</p> <p>I find that erb is installed:</p> <pre><code># file /usr/lib/ruby/1.9.1/erb.rb /usr/lib/ruby/1.9.1/erb.rb: ASCII English text </code></pre> <p>and it was installed along with ruby:</p> <pre><code># dpkg -S /usr/lib/ruby/1.9.1/erb.rb libruby1.9.1: /usr/lib/ruby/1.9.1/erb.rb </code></pre> <p>I am running below sample code which is provided in <code>/usr/lib/ruby/1.9.1/erb.rb</code></p> <pre><code>#!/usr/bin/ruby require 'erb' x = 42 template = ERB.new &lt;&lt;-EOF The value of x is: &lt;%= x %&gt; EOF puts template.result(binding) </code></pre> <p>I get below error when I run the code:</p> <pre><code>/workspace/ruby/erb.rb:4:in `&lt;top (required)&gt;': uninitialized constant ERB (NameError) from /workspace/ruby/erb.rb:2:in `require' from /workspace/ruby/erb.rb:2:in `&lt;main&gt;' </code></pre> <p><strong>Question:</strong> what is missing in above code?</p> <p>Here is my platform:</p> <pre><code># lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 10.04.4 LTS Release: 10.04 Codename: lucid # uname -m i686 </code></pre> <p>and my ruby version:</p> <pre><code># ruby -v ruby 1.9.1p378 (2010-01-10 revision 26273) [i486-linux] </code></pre> <p><strong>ANSWER:</strong></p> <p>@matt's comment is answer to this question. I had named my script as <code>erb.rb</code> and that was the problem. I renamed it to <code>testing_erb.rb</code> and it worked. Please check matt's comment for more details.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload