# Whyhtml.erb generate a html structure not like it should be?

**URL:** <https://www.ruby-forum.com/t/whyhtml-erb-generate-a-html-structure-not-like-it-should-be/192370>\
**Category:** Rails\
**Created:** [July 29, 2010, 5:19am UTC](https://www.ruby-forum.com/t/whyhtml-erb-generate-a-html-structure-not-like-it-should-be/192370 "2010-07-29T05:19:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubyernewbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9dc877/32.png) [@rubyernewbie](https://www.ruby-forum.com/u/rubyernewbie)\
**Post date:** [July 29, 2010, 5:19am UTC](https://www.ruby-forum.com/t/whyhtml-erb-generate-a-html-structure-not-like-it-should-be/192370/1 "2010-07-29T05:19:33Z")

</div>

the HTML.ERB like this, and then it generate a html, it. the

  
indent not it shoud be, and the second 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\_title
  
\<% unless @obs.blank? -%\>  

|
| |

  
  
  
  
  
  
  
\<% @obs.each do |ob| -%\>  
  
  
  
  
  
  
\<% end -%\>  

| data | state | number | operation |
| --- | --- | --- | --- |
| \<%= ob.created\_at %\> | \<%= ob.state %\> | ob.number | ob.operation |

  
\<% 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>

```

====================

---

<div class="post-metadata">

**Author:** ![rubyernewbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9dc877/32.png) [@rubyernewbie](https://www.ruby-forum.com/u/rubyernewbie)\
**Post date:** [July 29, 2010, 8:47am UTC](https://www.ruby-forum.com/t/whyhtml-erb-generate-a-html-structure-not-like-it-should-be/192370/2 "2010-07-29T08:47:42Z")

</div>

On 29 July 2010 04:19, Zhenning G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the HTML.ERB like this, and then it generate a html, it. the
> 
>   
> indent not it shoud be, and the second 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\_title
> \<% unless @obs.blank? -%\> 
> 
> |
> | |
> 
> \<% @obs.each do |ob| -%\> \<% end -%\> 
> 
> | operation |
> | --- |
> | \<%= ob.created\_at %\> |
> 
> \<% 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 🙂
