Zhenning Guan
2010-Jul-29 03:19 UTC
whyhtml.erb generate a html structure not like it should be?
the HTML.ERB like this, and then it generate a html, it. the <table> indent not it shoud be, and the second <tr> also indent not the noraml. why it generate a html like that? second, I think everytme I should check empty object like object.blank? and then iterate the object is very ugly. how to change this ugly behavior? ========= <h1>h1_title</h1> <% unless @obs.blank? -%> <table border="0" cellspacing="0" class="normal_table"> <tr> <th>data</th> <th>state</th> <th>number</th> <th>operation</th> </tr> <% @obs.each do |ob| -%> <tr> <td><%= ob.created_at %></td> <td><%= ob.state %></td> <td class="info">ob.number</td> <td>ob.operation</td> </tr> <% end -%> </table> <% end -%> ============================================ <h1>h1_title</h1> <table border="0" cellspacing="0" class="normal_table"> <tr> <th>data</th> <th>state</th> <th>number</th> <th>operation</th> </tr> <tr> <td>2010-07-27</td> <td>initialize</td> <td class="info">1</td> <td>un_done</td> </tr> </table> ===================-- Posted via http://www.ruby-forum.com/. -- 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.
Michael Pavling
2010-Jul-29 06:45 UTC
Re: whyhtml.erb generate a html structure not like it should be?
On 29 July 2010 04:19, Zhenning Guan <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> the HTML.ERB like this, and then it generate a html, it. the <table> > indent not it shoud be, and the second <tr> also indent not the noraml. > why it generate a html like that?Your Ruby code is indented (it has some whitepace infront) and then you suppress whitespace at the end. So the next line (which is indented) starts directly after the previous indents. Two choices: 1) Don''t worry about it. I''d rather have nicely laid out code than prioritise nicely laid out HTML. 2) Remove the code indents: <h1>h1_title</h1> <% unless @obs.blank? -%> <table border="0" cellspacing="0" class="normal_table"> <tr> <th>operation</th> </tr> <% @obs.each do |ob| -%> <tr> <td><%= ob.created_at %></td> </tr> <% end -%> </table> <% end -%>> second, I think everytme I should check empty object like object.blank? > and then iterate the object is very ugly. how to change this ugly > behavior?Seems reasonable to me; not so ugly. But you could move the "@obs.each" row out to a partial and pass in @obs as the collection. It does the same thing, but might look "prettier" to you :-) -- 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.