Ahmad hamza
Ahmad hamza

Reputation: 1936

If else condition not working properly?

This is my code in which i want to display the book details taken from the book table.

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

But i dont knot what is going wrong here with the output?

It is displaying like this. Take notice of the long line of each row. After editing i get this much.

Ok this is something abnormal going on in the terminal

http://pastie.org/5134510 Notice the second row. Thanks

Upvotes: 1

Views: 207

Answers (1)

u8sand
u8sand

Reputation: 574

I modified it to fix some problems with the table formatting.

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

as for the problem with the details, I am unsure as to why the bottom result is aligned to the right. Something I'd say was a CSS problem normally but why is it changing for each entry I don't know.

Upvotes: 2

Related Questions