string substitution

B

Barry Abrams

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.
 
P

Phrogz

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
 
J

John Joyce

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
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top