Skip to content

Commit

Permalink
Books user is borrowing and books that are borrowed.
Browse files Browse the repository at this point in the history
  • Loading branch information
oestrich committed Dec 3, 2010
1 parent c2a66be commit 95cf5b4
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/controllers/users_controller.rb
@@ -0,0 +1,20 @@
class UsersController < ApplicationController

load_and_authorize_resource

def index

end

def borrowing
@user = current_user
@books = Book.where(:borrower_user_id => @user.id)

end

def borrowed
@user = current_user

end

end
6 changes: 6 additions & 0 deletions app/models/ability.rb
Expand Up @@ -14,6 +14,9 @@ def initialize(user)
if user.role == "admin"
can :manage, :all
can :about, Book

can :borrowed, User
can :borrowing, User
end

if user.role == "user"
Expand All @@ -28,6 +31,9 @@ def initialize(user)

can :read, Location
can :about, Book

can :borrowed, User
can :borrowing, User
end

if user.role == "guest"
Expand Down
4 changes: 4 additions & 0 deletions app/views/shared/_header.html.erb
@@ -1,6 +1,10 @@
<div id="user_nav">
<% if user_signed_in? %>
Signed in as <%= link_to "#{current_user.email}", edit_user_registration_path %> Not you? <%= link_to "Sign out", destroy_user_session_path %>
<br />
<%= link_to "Books borrowed from me", users_borrowed_path %>
<br />
<%= link_to "Books I'm borrowing", users_borrowing_path %>
<% else %>
<%= link_to "Sign up", new_user_registration_path %> or <%= link_to "Sign in", new_user_session_path %>
<% end %>
Expand Down
24 changes: 24 additions & 0 deletions app/views/users/borrowed.html.erb
@@ -0,0 +1,24 @@

<h1> Books being borrowed </h1>
<% current_user.locations.each do |location| %>
<div class='location'>
<% has_books = false %>
<br />
<h1><b><%= link_to location.name, "/locations/#{location.id}" %></b></h1>
<br />
<% location.books.each do |book| %>
<% if book.borrower_user_id != nil %>
<% has_books = true %>
<% buser = User.find(book.borrower_user_id) %>
<div class='book_borrowed'>
<%= link_to image_tag(book.image_url), book, :title => "#{buser.first_name} #{buser.last_name} is borrowing this book." %>
</div>
<% end %>
<% end %>
<% if has_books == false %>
No books are being borrowed in this location.
<% end %>
</div>
<% end %>

5 changes: 5 additions & 0 deletions app/views/users/borrowing.html.erb
@@ -0,0 +1,5 @@
<% @books.each do |book| %>
<div class='book_borrowed'>
<%= link_to image_tag(book.image_url), book, :title => "#{@user.first_name} #{@user.last_name} is borrowing this book." %>
</div>
<% end %>
1 change: 1 addition & 0 deletions app/views/users/index.html.erb
@@ -0,0 +1 @@
Hello, world!
Empty file added app/views/users/show.html.erb
Empty file.
7 changes: 6 additions & 1 deletion config/routes.rb
@@ -1,10 +1,15 @@
Bookshare::Application.routes.draw do
resources :locations

devise_for :users

match 'users/borrowing' => 'users#borrowing', :as => :users_borrowing
match 'users/borrowed' => 'users#borrowed', :as => :users_borrowed
resources :users


resources :books


root :to => "books#index"

# The priority is based upon order of creation:
Expand Down

0 comments on commit 95cf5b4

Please sign in to comment.