String substitution

Sorry if this question gets posted a lot. I'm unsure of the terminology,
so my searches didn't come up with anything.

I've got a block of html coming in from the database that looks like
this:

<div style="float:left; width:33%">
#{@copy_1}
</div>

<div style="float:left; width:33%">
#{@copy_2}
</div>

<div style="float:left; width:33%">
#{@copy_3}
</div>

I'd like to replace the variables with another string, which contains
just text.

What's the syntax for something like this? I got gsub! to do one
variable, but it didn't seem like it was the most efficient way to do
it. Plus, I need to do multiple ones.

···

--
Posted via http://www.ruby-forum.com/.

Does it have to look like that? Could it instead look like this?
  <div style="float:left; width:33%">
  <%=@copy_1%>
  </div>

If so, you want ERB. Roughly:

require 'erb'
template = #...stuff from the DB
html = ERB.new( template ).result

···

On May 8, 3:36 pm, Barry Abrams <barrysf...@gmail.com> wrote:

I've got a block of html coming in from the database that looks like
this:

<div style="float:left; width:33%">
#{@copy_1}
</div>

You might also consider moving the style attributes out of the div elements. Put them in one place. No use repeating the same thing again and again. Ideally even move it all to a style sheet outside of the html. More flexibility.

···

On May 9, 2007, at 7:00 AM, Phrogz wrote:

On May 8, 3:36 pm, Barry Abrams <barrysf...@gmail.com> wrote:

I've got a block of html coming in from the database that looks like
this:

<div style="float:left; width:33%">
#{@copy_1}
</div>

Does it have to look like that? Could it instead look like this?
  <div style="float:left; width:33%">
  <%=@copy_1%>
  </div>

If so, you want ERB. Roughly:

require 'erb'
template = #...stuff from the DB
html = ERB.new( template ).result