-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding books by all users + UI enhancements
- Loading branch information
1 parent
fe2ef12
commit ae9b9f1
Showing
12 changed files
with
54 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ class Book < ActiveRecord::Base | |
end | ||
|
||
has_many :rentals | ||
belongs_to :user | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<tr id="book-row-<%= book.id %>"> | ||
<td><%= link_to book.name, book %></td> | ||
<td><%= book.author %></td> | ||
<td><%= book.sku %></td> | ||
<td><span class="<%= get_bootstrap_class_for_state book.state %>"><%= book.state %></span></td> | ||
<td> | ||
<%= link_to('Rent', rentals_path(sku: book.sku, format: :js), method: :post, remote: true) if can? :create, Rental and book.active? %> | ||
<%= link_to('Return', rental_path(book.rentals.active.first, format: :js), method: :delete, remote: true) if can? :destroy, Rental and book.rented? %> | ||
</td> | ||
<td><%= link_to('Edit', edit_book_path(book)) if can? :edit, book %></td> | ||
<td><%= link_to('Delete', book_path(book, format: :js), method: :delete, data: { confirm: 'Are you sure you want to remove this item from library?' }, remote: true) if can? :destroy, book %></td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% if @rental.errors.any? %> | ||
alert('This book cannot be returned.'); | ||
<% else %> | ||
$('#book-row-<%= @rental.book.id %>').replaceWith("<%= j render(partial: 'books/books_row', locals: {book: @rental.book}).html_safe %>"); | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% if @rental.errors.any? %> | ||
alert('This book cannot be rented.'); | ||
<% else %> | ||
$('#book-row-<%= @rental.book.id %>').replaceWith("<%= j render(partial: 'books/books_row', locals: {book: @rental.book}).html_safe %>"); | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddUserToBook < ActiveRecord::Migration | ||
def change | ||
add_reference :books, :user, index: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,4 +52,4 @@ | |
b.author = 'Lauren Groff Van Thomson Pierson Writerson' | ||
b.sku = '12352' | ||
b.state = :active | ||
end | ||
end |