Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.13 KB | None | 0 0
  1. <%
  2. if @user
  3. %>
  4. <h1>Welcome <% @user.username %> </h1>
  5. <%
  6. else
  7. %>
  8. <h1>Welcome Guest</h1>
  9. <% link_to 'Login', :controller => 'users', :action => 'login' %>
  10. <%
  11. end
  12. %>
  13. <!-- the above section does not see the @user variable correctly -->
  14. <h1>Listing books</h1>
  15.  
  16. <table>
  17.   <tr>
  18.     <th>Title</th>
  19.     <th>Author</th>
  20.     <th>Cover</th>
  21.     <th>Price</th>
  22.     <th>Stock</th>
  23.   </tr>
  24.  
  25. <% @books.each do |book| %>
  26.   <tr>
  27.     <td><%=h book.title %></td>
  28.     <td><%=h book.author %></td>
  29.     <td><%=h book.cover %></td>
  30.     <td><%=h book.price %></td>
  31.     <td><%=h book.stock %></td>
  32. <!-- The code bellow works as expected, having the correct value for @user -->
  33.     <%
  34.     if @user
  35.     %>
  36.     <td><%= link_to 'Show', book %></td>
  37.     <% end %>
  38.     <%
  39.     if @user
  40.         if @user.admin == 1
  41.     %>
  42.     <td><%= link_to 'Edit', edit_book_path(book) %></td>
  43.     <td><%= link_to 'Delete', book, :confirm => 'Are you sure?', :method => :delete %></td>
  44.     <%
  45.       end
  46.     end
  47.     %>
  48.   </tr>
  49. <% end %>
  50. </table>
  51.  
  52. <br />
  53. <%
  54. if @user
  55.   if @user.admin == 1
  56. %>
  57. <%= link_to 'New book', new_book_path %>
  58. <%
  59.   end
  60. end
  61. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement