Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%
- if @user
- %>
- <h1>Welcome <% @user.username %> </h1>
- <%
- else
- %>
- <h1>Welcome Guest</h1>
- <% link_to 'Login', :controller => 'users', :action => 'login' %>
- <%
- end
- %>
- <!-- the above section does not see the @user variable correctly -->
- <h1>Listing books</h1>
- <table>
- <tr>
- <th>Title</th>
- <th>Author</th>
- <th>Cover</th>
- <th>Price</th>
- <th>Stock</th>
- </tr>
- <% @books.each do |book| %>
- <tr>
- <td><%=h book.title %></td>
- <td><%=h book.author %></td>
- <td><%=h book.cover %></td>
- <td><%=h book.price %></td>
- <td><%=h book.stock %></td>
- <!-- The code bellow works as expected, having the correct value for @user -->
- <%
- if @user
- %>
- <td><%= link_to 'Show', book %></td>
- <% end %>
- <%
- if @user
- if @user.admin == 1
- %>
- <td><%= link_to 'Edit', edit_book_path(book) %></td>
- <td><%= link_to 'Delete', book, :confirm => 'Are you sure?', :method => :delete %></td>
- <%
- end
- end
- %>
- </tr>
- <% end %>
- </table>
- <br />
- <%
- if @user
- if @user.admin == 1
- %>
- <%= link_to 'New book', new_book_path %>
- <%
- end
- end
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement