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]} </span>"   end   @content = "<div style=\"font-size:100;color:blue;\">" + @content + "</div>"

  @txt_divs = ""   for i in 0..5     span = ""     for j in 0..10       span = "#{span} <span id='sp#{i}_#{j}' style='display:none'> </

"

    end     div = "<div> #{span} </div>"     @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:

&lt;div style=&quot;font-size:100;color:blue;&quot;&gt;&lt;span id=&quot;w0&quot; style='display:none'&gt; Free &lt;/span&gt;&lt;span id=&quot;w1&quot; style='display:none'&gt; Spirit &lt;/ span&gt;&lt;span id=&quot;w2&quot; style='display:none'&gt; Boston &lt;/span&gt;&lt;span id=&quot;w3&quot; style='display:none'&gt; &lt;/ span&gt;&lt;/div&gt;

&lt;div&gt; &lt;span id='sp0_0' style='display:none'&gt; &lt;/ span&gt; &lt;span id='sp0_1' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp0_2' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp0_3' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp0_4' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp0_5' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp0_6' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp0_7' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp0_8' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp0_9' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp0_10' style='display:none'&gt; &lt;/span&gt; &lt;/div&gt;

&lt;div&gt; &lt;span id='sp1_0' style='display:none'&gt; &lt;/ span&gt; &lt;span id='sp1_1' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp1_2' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp1_3' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp1_4' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp1_5' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp1_6' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp1_7' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp1_8' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp1_9' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp1_10' style='display:none'&gt; &lt;/span&gt; &lt;/div&gt;

&lt;div&gt; &lt;span id='sp2_0' style='display:none'&gt; &lt;/ span&gt; &lt;span id='sp2_1' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp2_2' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp2_3' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp2_4' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp2_5' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp2_6' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp2_7' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp2_8' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp2_9' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp2_10' style='display:none'&gt; &lt;/span&gt; &lt;/div&gt;

&lt;div&gt; &lt;span id='sp3_0' style='display:none'&gt; &lt;/ span&gt; &lt;span id='sp3_1' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp3_2' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp3_3' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp3_4' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp3_5' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp3_6' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp3_7' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp3_8' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp3_9' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp3_10' style='display:none'&gt; &lt;/span&gt; &lt;/div&gt;

&lt;div&gt; &lt;span id='sp4_0' style='display:none'&gt; &lt;/ span&gt; &lt;span id='sp4_1' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp4_2' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp4_3' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp4_4' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp4_5' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp4_6' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp4_7' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp4_8' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp4_9' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp4_10' style='display:none'&gt; &lt;/span&gt; &lt;/div&gt;

&lt;div&gt; &lt;span id='sp5_0' style='display:none'&gt; &lt;/ span&gt; &lt;span id='sp5_1' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp5_2' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp5_3' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp5_4' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp5_5' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp5_6' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp5_7' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp5_8' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp5_9' style='display:none'&gt; &lt;/span&gt; &lt;span id='sp5_10' style='display:none'&gt; &lt;/span&gt; &lt;/div&gt;

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]} </span>" end @content = "<div style=\"font-size:100;color:blue;\">" + @content + "</div>"

@txt_divs = "" for i in 0..5    span = ""    for j in 0..10      span = "#{span} <span id='sp#{i}_#{j}' style='display:none'> </ >"    end    div = "<div> #{span} </div>"    @txt_divs << div << "\n" end

In the view I then do this:

<%= @content%>

<%= @txt_divs %>

<%= raw @content %>

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

-philip

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

Specifically, check out section 3.4.5, “Rendering Collections”