2012-10-29 37 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