views:

38

answers:

2

I am using Rails 2.1 to output tables from a database. But the output includes lots of extra lines and tabs. I am using a while loop with lots of nested if statements. I am also wrapping all of my non-output lines in <%- code -%>. Any idea what might be happening and a solution? Thanks,

NOTE: I keep attempting to paste in the code, and while the preview looks good, upon save, the formatting is unreadable....

<%- while row_no < total_rows  -%>
 <tr class="<%=h @row_styles[row_no] %>">
  <%- @cells.each do |ce| -%>           
   <%- if row_no == ce.row_id -%> 
    <%- if @col_styles[ce.column_id] == '' -%>
     <%- if ce.additional_info.blank? -%>
      <td><%= ce.content %></td>
A: 

I think you need to post some code for an effective diagnostics. Please reduce your template to a small sample displaying the issue.

I'm sure the generated whitespace you are seeing is from the text outside tge <%- -%>-tags. For a low-tech approach, try adding visible characters in the current whitespace, and see how it is reproduced in the output.

laust.rud
+1  A: 

It would help a lot to consolidate successive lines of Ruby into a single code block:

<%- while row_no < total_rows  -%>
 <tr class="<%=h @row_styles[row_no] %>">
  <%- @cells.each do |ce|
        if row_no == ce.row_id
          if @col_styles[ce.column_id] == ''
            if ce.additional_info.blank? -%>
   <td><%= ce.content %></td>

Also, all those nested ifs suggest to me that your implementation could use some work. Can you combine any of those into single conditionals?

Jordan