From: dominic sisneros Date: 2004-07-26T15:03:16+09:00 Subject: Re: [ANN] Rails 0.5.0: The end of vaporware! Sorry, I tried to do it from memory and got the format juxtaposed. Instead of <%h= "something with %> should be <%=h "something with %> See below require 'erb' class Foo include ERB::Util SCRIPT = <<%=h @name %>
    <% ary.each do |x|%>
  • <%=h x %>
  • <% end %>
EOS def initialize(name) @name = name @erb = ERB.new(SCRIPT) end def foo(ary) @erb.result(binding) end end it = Foo.new('foo') puts it.foo([1,2,'']) On Jul 25, 2004, at 10:39 PM, Jamis Buck wrote: > dominic sisneros wrote: >> If you include ERB::Util then it includes html escape. Use it in your >> templates like this >> <%h= puts "Some text with " %> > > Could you give a longer example? I tried the following and didn't get > what I expected... > > require 'erb' > include ERB::Util > > @text = "something with and \"quotes\"" > erb = ERB.new( "This is <%h= @text %>" ) > p erb.result > #-> "This is " > > - Jamis > > -- > Jamis Buck > jgb3@email.byu.edu > http://www.jamisbuck.org/jamis > > "I use octal until I get to 8, and then I switch to decimal." > >