Trying to figure out generating html in controller

So I have some old code that used to work and I am trying to
resurrect it.

The controller has this:

@content=""
for i in 0…w.size
@content = @content + "<span id=“w#{i}” style=‘display:none’>
#{w[i]} "
end
@content = “<div style=“font-size:100;color:blue;”>” + @content +
“”

@txt_divs = “”
for i in 0…5
span = “”
for j in 0…10
span = “#{span} </
span>”
end
div = "

#{span}
"
@txt_divs << div << “\n”
end

In the view I then do this:

<%= @content%>

<%= @txt_divs %>

but what’s get generated is this as literal text and not what I wanted
or what used to work:

<div style=“font-size:100;color:blue;”><span
id=“w0” style=‘display:none’> Free </span><span
id=“w1” style=‘display:none’> Spirit </
span><span id=“w2” style=‘display:none’> Boston
</span><span id=“w3” style=‘display:none’> </
span></div>

<div> <span id=‘sp0_0’ style=‘display:none’> </
span> <span id=‘sp0_1’ style=‘display:none’> </span>
<span id=‘sp0_2’ style=‘display:none’> </span> <span
id=‘sp0_3’ style=‘display:none’> </span> <span id=‘sp0_4’
style=‘display:none’> </span> <span id=‘sp0_5’
style=‘display:none’> </span> <span id=‘sp0_6’
style=‘display:none’> </span> <span id=‘sp0_7’
style=‘display:none’> </span> <span id=‘sp0_8’
style=‘display:none’> </span> <span id=‘sp0_9’
style=‘display:none’> </span> <span id=‘sp0_10’
style=‘display:none’> </span> </div>

<div> <span id=‘sp1_0’ style=‘display:none’> </
span> <span id=‘sp1_1’ style=‘display:none’> </span>
<span id=‘sp1_2’ style=‘display:none’> </span> <span
id=‘sp1_3’ style=‘display:none’> </span> <span id=‘sp1_4’
style=‘display:none’> </span> <span id=‘sp1_5’
style=‘display:none’> </span> <span id=‘sp1_6’
style=‘display:none’> </span> <span id=‘sp1_7’
style=‘display:none’> </span> <span id=‘sp1_8’
style=‘display:none’> </span> <span id=‘sp1_9’
style=‘display:none’> </span> <span id=‘sp1_10’
style=‘display:none’> </span> </div>

<div> <span id=‘sp2_0’ style=‘display:none’> </
span> <span id=‘sp2_1’ style=‘display:none’> </span>
<span id=‘sp2_2’ style=‘display:none’> </span> <span
id=‘sp2_3’ style=‘display:none’> </span> <span id=‘sp2_4’
style=‘display:none’> </span> <span id=‘sp2_5’
style=‘display:none’> </span> <span id=‘sp2_6’
style=‘display:none’> </span> <span id=‘sp2_7’
style=‘display:none’> </span> <span id=‘sp2_8’
style=‘display:none’> </span> <span id=‘sp2_9’
style=‘display:none’> </span> <span id=‘sp2_10’
style=‘display:none’> </span> </div>

<div> <span id=‘sp3_0’ style=‘display:none’> </
span> <span id=‘sp3_1’ style=‘display:none’> </span>
<span id=‘sp3_2’ style=‘display:none’> </span> <span
id=‘sp3_3’ style=‘display:none’> </span> <span id=‘sp3_4’
style=‘display:none’> </span> <span id=‘sp3_5’
style=‘display:none’> </span> <span id=‘sp3_6’
style=‘display:none’> </span> <span id=‘sp3_7’
style=‘display:none’> </span> <span id=‘sp3_8’
style=‘display:none’> </span> <span id=‘sp3_9’
style=‘display:none’> </span> <span id=‘sp3_10’
style=‘display:none’> </span> </div>

<div> <span id=‘sp4_0’ style=‘display:none’> </
span> <span id=‘sp4_1’ style=‘display:none’> </span>
<span id=‘sp4_2’ style=‘display:none’> </span> <span
id=‘sp4_3’ style=‘display:none’> </span> <span id=‘sp4_4’
style=‘display:none’> </span> <span id=‘sp4_5’
style=‘display:none’> </span> <span id=‘sp4_6’
style=‘display:none’> </span> <span id=‘sp4_7’
style=‘display:none’> </span> <span id=‘sp4_8’
style=‘display:none’> </span> <span id=‘sp4_9’
style=‘display:none’> </span> <span id=‘sp4_10’
style=‘display:none’> </span> </div>

<div> <span id=‘sp5_0’ style=‘display:none’> </
span> <span id=‘sp5_1’ style=‘display:none’> </span>
<span id=‘sp5_2’ style=‘display:none’> </span> <span
id=‘sp5_3’ style=‘display:none’> </span> <span id=‘sp5_4’
style=‘display:none’> </span> <span id=‘sp5_5’
style=‘display:none’> </span> <span id=‘sp5_6’
style=‘display:none’> </span> <span id=‘sp5_7’
style=‘display:none’> </span> <span id=‘sp5_8’
style=‘display:none’> </span> <span id=‘sp5_9’
style=‘display:none’> </span> <span id=‘sp5_10’
style=‘display:none’> </span> </div>

On May 24, 2011, at 12:16 PM, Jedrin wrote:

end
div = "

#{span}
"

<%= @txt_divs %>

<%= raw @content %>

Seems like you should move that into the view if you can though…

-philip

On Tuesday, May 24, 2011 1:33:26 PM UTC-6, Philip wrote:

@content=""
for j in 0…10
In the view I then do this:
-philip

Additionally, as you take Philip’s suggestion, you ought to consider the
power of using partials:

http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials

Specifically, check out section 3.4.5, “Rendering Collections”

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