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''> </ span>" 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: <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> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2011-May-24 19:33 UTC
Re: Trying to figure out generating html in controller
On May 24, 2011, at 12:16 PM, Jedrin wrote:> > 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''> </ > span>" > 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> > 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> > > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Kendall Gifford
2011-May-24 22:21 UTC
Re: Trying to figure out generating html in controller
On Tuesday, May 24, 2011 1:33:26 PM UTC-6, Philip wrote:> > > On May 24, 2011, at 12:16 PM, Jedrin wrote: > > > > > 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''> </ > > span>" > > 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: http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials Specifically, check out section 3.4.5, "Rendering Collections" -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.