Skip to content

Commit

Permalink
Update display to agreed look, feel, and functionality
Browse files Browse the repository at this point in the history
The application will focus on the book list, and book detail pages.
Adding a new issue will happen on the book detail page.
Editing or deleting an issue will be up to frontend implementors.
  • Loading branch information
blowmage committed Aug 15, 2013
1 parent 78c214d commit 87a840c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 54 deletions.
4 changes: 2 additions & 2 deletions app/controllers/issues_controller.rb
Expand Up @@ -29,7 +29,7 @@ def create

respond_to do |format|
if @issue.save
format.html { redirect_to [@book, @issue], notice: 'Issue was successfully created.' }
format.html { redirect_to [@book], notice: 'Issue was successfully created.' }
format.json { render action: 'show', status: :created, location: @issue }
else
format.html { render action: 'new' }
Expand Down Expand Up @@ -57,7 +57,7 @@ def update
def destroy
@issue.destroy
respond_to do |format|
format.html { redirect_to book_issues_url(@book) }
format.html { redirect_to book_url(@book) }
format.json { head :no_content }
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/book.rb
@@ -1,3 +1,5 @@
class Book < ActiveRecord::Base
has_many :issues

default_scope { order(:name) }
end
2 changes: 2 additions & 0 deletions app/models/issue.rb
@@ -1,3 +1,5 @@
class Issue < ActiveRecord::Base
belongs_to :book

default_scope { order(:number) }
end
41 changes: 11 additions & 30 deletions app/views/books/index.html.erb
@@ -1,31 +1,12 @@
<h1>All Books</h1>

<table>
<thead>
<tr>
<th>Name</th>
<th>Cover image url</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

<tbody>
<% @books.each do |book| %>
<tr>
<td><%= book.name %></td>
<td><%= book.cover_image_url %></td>
<td><%= link_to 'Show', book %></td>
<td><%= link_to pluralize(book.issues.count, 'Issue'), book_issues_path(book) %></td>
<td><%= link_to 'Edit', edit_book_path(book) %></td>
<td><%= link_to 'Destroy', book, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% @books.in_groups_of(3, false) do |books| %>
<div class="row">
<% books.each do |book| %>
<div class="span3">
<h4><%= book.name %> - <%= pluralize(book.issues.count, 'Issue') %></h4>
<%= link_to book_path(book) do %>
<%= image_tag book.cover_image_url %>
<% end %>
</div>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Book', new_book_path %>
</div>
<% end %>
53 changes: 43 additions & 10 deletions app/views/books/show.html.erb
@@ -1,15 +1,48 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Name:</strong>
<h1>
<%= @book.name %>
</p>
<div class="btn-group pull-right">
<%= link_to 'Edit', edit_book_path(@book), class: "btn" %>
<%= link_to 'Destroy', @book, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn" %>
</div>
</h1>

<p>
<strong>Cover image url:</strong>
<%= @book.cover_image_url %>
</p>
<p><%= pluralize(@book.issues.count, 'Issue') %></p>

<%= link_to pluralize(@book.issues.count, 'Issue'), book_issues_path(@book) %> |
<%= link_to 'Edit', edit_book_path(@book) %> |
<%= link_to 'Back', books_path %>
<p><%= number_to_currency(@book.issues.sum(:price)) %> Total</p>

<div id="book_<%= @book.id %>_issues">
<% @book.issues.in_groups_of(4, false) do |row_issues| %>
<div class="row-fluid">
<% row_issues.each do |issue| %>
<div class="span3">
<%= div_for issue do %>
<h4><%= issue.title %></h4>
<%= link_to book_issue_path(issue.book, issue) do %>
<%= image_tag issue.cover_image_url %>
<% end %>
<% end %>
</div>
<% end %>
</div>
<% end %>
</div>

<hr>

<%= simple_form_for([@book, @book.issues.new]) do |f| %>
<fieldset>
<legend><%= controller.action_name.capitalize %> Product</legend>

<%= f.input :number %>
<%= f.input :title %>
<%= f.input :cover_image_url %>
<%= f.input :price %>

<div class="form-actions">
<%= f.submit nil, :class => 'btn btn-primary' %>
<%= link_to 'Cancel', books_path(@book), :class => 'btn' %>
</div>
</fieldset>
<% end %>
20 changes: 11 additions & 9 deletions app/views/issues/show.html.erb
@@ -1,8 +1,18 @@
<p id="notice"><%= notice %></p>

<h1>
<%= @book.name %>
<div class="btn-group pull-right">
<%= link_to 'Edit', edit_book_issue_path(@book, @issue), class: "btn" %>
<%= link_to 'Destroy', book_issue_path(@book, @issue), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn" %>
</div>
</h1>

<%= image_tag @issue.cover_image_url, class: "pull-right" %>

<p>
<strong>Book:</strong>
<%= @book.name %>
<%= link_to @book.name, book_path(@book) %>
</p>

<p>
Expand All @@ -15,15 +25,7 @@
<%= @issue.title %>
</p>

<p>
<strong>Cover image url:</strong>
<%= @issue.cover_image_url %>
</p>

<p>
<strong>Price:</strong>
<%= @issue.price %>
</p>

<%= link_to 'Edit', edit_book_issue_path(@book, @issue) %> |
<%= link_to 'Back', book_issue_path(@book, @issue) %>
5 changes: 4 additions & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -41,7 +41,10 @@
<ul class="nav nav-list">
<li class="nav-header">Books</li>
<% Book.all.each do |book| %>
<li><%= link_to book.name, book_path(book) %></li>
<li>
<span class="badge pull-right"><%= book.issues.count %></span>
<%= link_to book.name, book_path(book) %>
</li>
<% end %>
<li><%= link_to "New Book", new_book_path, class: "btn" %></li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/issues_controller_test.rb
Expand Up @@ -22,7 +22,7 @@ class IssuesControllerTest < ActionController::TestCase
post :create, book_id: @book, issue: { book_id: @issue.book_id, cover_image_url: @issue.cover_image_url, number: @issue.number, price: @issue.price, title: @issue.title }
end

assert_redirected_to book_issue_path(@book, assigns(:issue))
assert_redirected_to book_path(@book)
end

test "should show issue" do
Expand All @@ -45,6 +45,6 @@ class IssuesControllerTest < ActionController::TestCase
delete :destroy, book_id: @book, id: @issue
end

assert_redirected_to book_issues_path(@book)
assert_redirected_to book_path(@book)
end
end

0 comments on commit 87a840c

Please sign in to comment.