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

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>

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

On 29 July 2010 04:19, Zhenning G. [email protected] 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 :slight_smile:

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