class Animal
def add(name)
(@animals ||= []) << name
end
def generate_template
erb = ERB.new(File.read("#{__dir__}/test.rhtml"),0,'<>')
erb.result(binding)
end
end
The documentation for the trim mode '<>' says "omit newline for lines starting with <% and ending in %>", and the animals.each line and its end have leading spaces before the <%, so the line doesn't start with <% - it starts with spaces (or some other white space character).
You can either change the template so the lines for which you want to suppress newlines start and end with the <% and %>:
Or you can use the trim mode of '>' which lets you have leading spaces because it checks only for the line ending with %>. This mode will let you indent your erb "nicely".
I think there is a </ul> tag missing too...
Hope this helps,
Mike
···
On Mar 16, 2014, at 3:33 PM, Arup Rakshit <lists@ruby-forum.com> wrote:
Ruby code :
require 'erb'
class Animal
def add(name)
(@animals ||= ) << name
end
def generate_template
erb = ERB.new(File.read("#{__dir__}/test.rhtml"),0,'<>')
erb.result(binding)
end
end
On Mar 16, 2014, at 3:33 PM, Arup Rakshit <lists@ruby-forum.com> wrote:
erb.result(binding)
</html>
<li> dog </li>
I passed `'<>'` to suppress the new lines, but I couldn't. What wrong I
did ?
The documentation for the trim mode '<>' says "omit newline for lines
starting with <% and ending in %>", and the animals.each line and its
end have leading spaces before the <%, so the line doesn't start with <%
- it starts with spaces (or some other white space character).
Read the doc wrongly. I thought doc is saying inside <% ... %>.