2012-10-29 35 views
1

這是我的代碼,我想要顯示書桌上的書籍細節。如果其他條件工作不正常?

<div class="tab-pane" id="computer"> <!-- Branch Computer --> 
     <legend> Computer Science</legend> 
      <table class ="table table-hover"> 
       <thead> 
        <tr> 
         <th> S.No </th> 
         <th> Book Name </th> 
         <th> Year </th> 
         <th> User ID</th> 
         <th> Owner Address</th> 
        </tr> 
       </thead> 
       <tbody> 
        <% @books.each do |b| %>          
        <tr> 
        <% if b.branch == "Computer Science"%> 
         <td><%= b.id%></td> 
         <td><%= b.book_name%></td> 
         <td><%= b.year%></td> 
         <td><%= b.user_id%></td> 
                <!-- For displaying user details -->        
         <% @susers.each do |s|%> 
          <% if s.user_id == b.user_id %> 
           <td><%= s.address %></td> 
          <%else%> 
           <td><%"Not found"%></td> 
          <%end%> 
          <%end%>       

         <%else%> 
           <td><%"No any book of this branch"%></td> 
         <%end%> 
         </tr>          
        <%end%> 
       </tbody>  
      </table>  
     </div><!-- End of Computer Branch--> 

但我不打結果在這裏輸出是什麼問題?

它是這樣顯示的。注意每行的長行。 編輯後,我得到這麼多。

確定這是什麼異常事情在終端

http://pastie.org/5134510 Notice the second row. 感謝

+0

你可能會張貼你的CSS,假設你說的問題是與你的表瘋狂的線我相信問題是在CSS中。與類表和tablehover和那些(td,th,tr,tbody's)的子定義 – u8sand

+0

實際上那些所有類都是twitter引導。他們剛纔提到要使用那些需要的類。 –

+0

第31行需要<>和<>或將它們放在if/else之外(在看完@SachinParasad的帖子之後) – u8sand

回答

2

我修改它來解決一些問題的表格格式。

<div class="tab-pane" id="computer"> <!-- Branch Computer --> 
      <legend> Computer Science</legend> 
       <table class ="table table-hover"> 
        <thead> 
         <tr> 
          <th> S.No </th> 
          <th> Book Name </th> 
          <th> Year </th> 
          <th> User ID</th> 
          <th> Owner Address</th> 
         </tr> 
        </thead> 
        <tbody> 
         <% @books.each do |b| %> 
         <% if b.branch == "Computer Science"%>          
         <tr> 
          <td><%= b.id%></td> 
          <td><%= b.book_name%></td> 
          <td><%= b.year%></td> 
          <td><%= b.user_id%></td> 
                 <!-- For displaying user details -->        
          <% @susers.each do |s|%> 
           <% if s.user_id == b.user_id %> 
            <td><%= s.address %></td> 
           <%else%> 
            <td><%"Not found"%></td> 
           <%end%> 
           <%end%> 
          <%end%> 
          </tr>          
         <%end%> 
        </tbody>  
       </table>  
      </div><!-- End of Computer Branch--> 

至於細節的問題,我不確定底層結果爲什麼對齊到右邊。我通常會說的是一個CSS問題,但爲什麼它會改變我不知道的每個條目。

+0

我在那裏粘貼了編輯後的代碼,但它再次顯示該表的其他類型的顯示。我只是想打印這本書的細節,但是因爲所有者詳細信息列正在從表中獲取詳細信息......因爲我寫了這個'<%​​@ susers.each do | s |%>' '<%if s .user_id == b.user_id%>'' ​​<%= s.address%>'' '<%else%>' ​​<% 「未找到」 %>'' '<%end%>' '<%end%>一些 –

+0

它如何進入循環。 –

+0

好的我修復了一點,看你的新輸出。關於右側的最後一項條款,我似乎無法弄清楚爲什麼會發生這種情況。嘗試使用更新後的代碼(應該使用新代碼去除頂部的額外行),並且會繼續查找問題。 – u8sand