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:

#{@copy_1}
#{@copy_2}
#{@copy_3}

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.

On May 8, 3:36 pm, Barry A. [email protected] wrote:

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

#{@copy_1}

Does it have to look like that? Could it instead look like this?

<%[email protected]_1%>

If so, you want ERB. Roughly:

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

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

<%[email protected]_1%>

If so, you want ERB. Roughly:

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs