3

I trying to build a table. Here is my HAML code:

%table{:border => 1}
%tbody
%tr
  %td Question:
- @cust_dashboard.each do |object|
  %tr
    %td= object.question
%tr
  %td Status:
- @cust_dashboard.each do |object|
  %tr
    %td= object.status
%tr
  %td Created_at:
- @cust_dashboard.each do |object|
  %tr
    %td= object.created_at

All the items in the table are in one column:

enter image description here

I need a table with three columns:

enter image description here

4

3 回答 3

11

I haven't written HAML for a while, but I think you want:

%table{:border => 1}
  %tbody
    %tr
      %td Question:
      %td Status:
      %td Created_at:
    - @cust_dashboard.each do |object|
      %tr
        %td= object.question
        %td= object.status
        %td= object.created_at

When building your template, think in terms of how the data will be emitted: We'd see:

<table>
  <tbody>
    <tr>
      <td>
      <td>
      <td>
    </tr>

Followed by a series of:

<tr>
  <td>
  <td>
  <td>
</tr>

(indented correctly of course) These would be each data row, three cells across.

I'd probably use th instead of td for the headers though:

%th Question:
%th Status:
%th Created_at:
于 2013-04-26T23:20:58.327 回答
0

每个tr人都会开始一个新的行,所以我认为你得到了你所要求的。

于 2013-04-26T23:00:53.570 回答
0

您每次都要求一个新行。

尝试改变:

- @cust_dashboard.each do |object|
  %tr
    %td= object.question

- @cust_dashboard.each do |object|
  %td= object.question
于 2013-04-26T23:01:02.350 回答