diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 238c363..d13c3ad 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -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' } @@ -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 diff --git a/app/models/book.rb b/app/models/book.rb index d445306..78525ff 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,3 +1,5 @@ class Book < ActiveRecord::Base has_many :issues + + default_scope { order(:name) } end diff --git a/app/models/issue.rb b/app/models/issue.rb index 6c0e7f4..33fd07a 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1,3 +1,5 @@ class Issue < ActiveRecord::Base belongs_to :book + + default_scope { order(:number) } end diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index 33074e5..2ab5319 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -1,31 +1,12 @@ -

All Books

- - - - - - - - - - - - - - - <% @books.each do |book| %> - - - - - - - - +<% @books.in_groups_of(3, false) do |books| %> +
+ <% books.each do |book| %> +
+

<%= book.name %> - <%= pluralize(book.issues.count, 'Issue') %>

+ <%= link_to book_path(book) do %> + <%= image_tag book.cover_image_url %> + <% end %> +
<% end %> -
-
NameCover image url
<%= book.name %><%= book.cover_image_url %><%= link_to 'Show', book %><%= link_to pluralize(book.issues.count, 'Issue'), book_issues_path(book) %><%= link_to 'Edit', edit_book_path(book) %><%= link_to 'Destroy', book, method: :delete, data: { confirm: 'Are you sure?' } %>
- -
- -<%= link_to 'New Book', new_book_path %> + +<% end %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 295861c..d4438fb 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -1,15 +1,48 @@

<%= notice %>

-

- Name: +

<%= @book.name %> -

+
+ <%= link_to 'Edit', edit_book_path(@book), class: "btn" %> + <%= link_to 'Destroy', @book, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn" %> +
+

-

- Cover image url: - <%= @book.cover_image_url %> -

+

<%= pluralize(@book.issues.count, 'Issue') %>

-<%= link_to pluralize(@book.issues.count, 'Issue'), book_issues_path(@book) %> | -<%= link_to 'Edit', edit_book_path(@book) %> | -<%= link_to 'Back', books_path %> +

<%= number_to_currency(@book.issues.sum(:price)) %> Total

+ +
+ <% @book.issues.in_groups_of(4, false) do |row_issues| %> +
+ <% row_issues.each do |issue| %> +
+ <%= div_for issue do %> +

<%= issue.title %>

+ <%= link_to book_issue_path(issue.book, issue) do %> + <%= image_tag issue.cover_image_url %> + <% end %> + <% end %> +
+ <% end %> +
+ <% end %> +
+ +
+ +<%= simple_form_for([@book, @book.issues.new]) do |f| %> +
+ <%= controller.action_name.capitalize %> Product + + <%= f.input :number %> + <%= f.input :title %> + <%= f.input :cover_image_url %> + <%= f.input :price %> + +
+ <%= f.submit nil, :class => 'btn btn-primary' %> + <%= link_to 'Cancel', books_path(@book), :class => 'btn' %> +
+
+<% end %> diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 23beb33..7d49d3d 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -1,8 +1,18 @@

<%= notice %>

+

+ <%= @book.name %> +
+ <%= 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" %> +
+

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

Book: - <%= @book.name %> + <%= link_to @book.name, book_path(@book) %>

@@ -15,15 +25,7 @@ <%= @issue.title %>

-

- Cover image url: - <%= @issue.cover_image_url %> -

-

Price: <%= @issue.price %>

- -<%= link_to 'Edit', edit_book_issue_path(@book, @issue) %> | -<%= link_to 'Back', book_issue_path(@book, @issue) %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 28ceb50..f69ed74 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -41,7 +41,10 @@ diff --git a/test/controllers/issues_controller_test.rb b/test/controllers/issues_controller_test.rb index c8f860a..221bf98 100644 --- a/test/controllers/issues_controller_test.rb +++ b/test/controllers/issues_controller_test.rb @@ -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 @@ -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