【问题标题】:If else condition not working properly?如果其他条件无法正常工作?
【发布时间】:2012-10-30 06:15:46
【问题描述】:

这是我的代码,我想在其中显示从图书表中获取的图书详细信息。

<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 谢谢

【问题讨论】:

  • 您是否可以发布您的 CSS,假设您正在谈论的问题是您的桌子上出现的疯狂线条我相信问题出在 CSS 中。带有类 table 和 tablehover 以及它们的子定义 (td,th,tr,tbody's)
  • 实际上所有的类都是 twitter bootstrap 的。他们刚刚提到在需要时使用这些类。
  • 第 31 行需要 > 和 > 或将它们放在 if/else 之外(查看 @SachinParasad 的帖子后)
  • 请您准确告诉我需要编辑的内容。因为第 31 行是 td 标签。

标签: ruby-on-rails-3.2


【解决方案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| %>
                        <% 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 问题,但为什么我不知道每个条目都会发生变化。

【讨论】:

  • 我将您编辑的代码粘贴到那里,但它再次显示该表格的其他类型的显示。我只是想打印这本书的详细信息,但由于所有者详细信息列正在从表格中获取详细信息..为此我写了这个&lt;% @susers.each do |s|%&gt;&lt;% if s.user_id == b.user_id %&gt;&lt;td&gt;&lt;%= s.address %&gt;&lt;/td&gt;``` `&lt;%end%&gt;``
  • 它是如何循环的。
  • 好的,我在查看您的新输出时对其进行了修复。就右侧的底部条目而言,我似乎无法弄清楚为什么会发生这种情况。尝试使用更新后的代码(新代码应该去掉顶部的多余行),我会继续寻找问题。
  • 我需要在我的终端中放置一些可疑的东西。我该怎么办?它没有大量的线条。
  • O_O 是你用我修改过的代码得到的吗??等等,你一定也事先得到了那个,对吧?该代码告诉我您的 if 语句总是错误的(有关详细信息),您确定数据库中的 id 正确吗?
猜你喜欢
  • 2022-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-09
  • 2014-11-07
相关资源
最近更新 更多