- <%= f.label :memo %>
- <%= f.text_area :memo %>
+
+Memo:
+
+
+
+
+
<%= f.label :purchased_on %>
<%= f.date_select :purchased_on %>
@@ -27,3 +31,10 @@
<%= f.submit %>
<% end %>
+
+
+
diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb
index 5f03ad6..8c40fd6 100644
--- a/app/views/books/index.html.erb
+++ b/app/views/books/index.html.erb
@@ -13,10 +13,8 @@
<% @books.each do |book| %>
| <%= book.title %> |
- <%= book.memo %> |
<%= book.purchased_on %> |
<%= link_to 'Show', book %> |
- <%= link_to 'Edit', edit_book_path(book) %> |
<%= link_to 'Destroy', book, confirm: 'Are you sure?', method: :delete %> |
<% end %>
diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb
index 23005ab..c71f8fa 100644
--- a/app/views/books/show.html.erb
+++ b/app/views/books/show.html.erb
@@ -4,17 +4,21 @@
Title:
<%= @book.title %>
-
- Memo:
- <%= @book.memo %>
+Memos:
+
+<% @book.memos.each do |m| %>
+
+ | <%= m.memo %> |
+
+
+<% end %>
+
-
Purchased on:
<%= @book.purchased_on %>
-<%= link_to 'Edit', edit_book_path(@book) %> |
<%= link_to 'Back', books_path %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 3bed8c4..4ae0ba0 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -3,7 +3,7 @@
BookMemo2
<%= stylesheet_link_tag "application", :media => "all" %>
- <%= javascript_include_tag "application" %>
+ <%= javascript_include_tag :application %>
<%= csrf_meta_tags %>
diff --git a/config/routes.rb b/config/routes.rb
index f3d38ab..af79db9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,4 +1,6 @@
BookMemo2::Application.routes.draw do
+ resources :memos
+
resources :books
# The priority is based upon order of creation:
diff --git a/db/migrate/20120526050801_create_books.rb b/db/migrate/20120526050801_create_books.rb
index b04e895..7ce3c86 100644
--- a/db/migrate/20120526050801_create_books.rb
+++ b/db/migrate/20120526050801_create_books.rb
@@ -1,8 +1,8 @@
class CreateBooks < ActiveRecord::Migration
def change
create_table :books do |t|
+ t.string :id
t.string :title
- t.text :memo
t.date :purchased_on
t.timestamps
diff --git a/db/schema.rb b/db/schema.rb
index 5fc61c2..733f304 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120526050801) do
+ActiveRecord::Schema.define(:version => 20120612123218) do
create_table "books", :force => true do |t|
t.string "title"
@@ -21,4 +21,11 @@
t.datetime "updated_at", :null => false
end
+ create_table "memos", :force => true do |t|
+ t.text "memo"
+ t.string "book_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
end
diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb
index f820855..25e6b97 100644
--- a/spec/models/book_spec.rb
+++ b/spec/models/book_spec.rb
@@ -11,11 +11,5 @@
end
end
- describe '#total_books_count' do
- let(:book){ FactoryGirl.build :book }
- before { book.save }
- it "memoに累計冊数が表示されること" do
- book.memo.should include "【 累計冊数#{Book.count} 】"
- end
- end
+
end
diff --git a/spec/requests/books_spec.rb b/spec/requests/books_spec.rb
index 37522b7..122baaa 100644
--- a/spec/requests/books_spec.rb
+++ b/spec/requests/books_spec.rb
@@ -10,6 +10,21 @@
end
end
+ describe "POST /books" do
+ it "creates a book" do
+ post_via_redirect books_path,
+ :book=>{:title=>"The road to the future",
+ :memos=>[{:memo=>"aaa"},{:memo=>"bbb"}],
+ :purchased_on(1i)=>"2012",
+ :purchased_on(2i)=>"6",
+ :purchased_on(3i)=>"13"
+ }
+ response.body.should include("mow lawn")
+ end
+ end
+
+
+
describe '/books/:id/edit' do
let!(:book){ FactoryGirl.create :book }
subject { page }