diff --git a/Gemfile b/Gemfile index d643000..dd7543e 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ group :assets do gem 'coffee-rails', '~> 3.2.1' # See https://github.com/sstephenson/execjs#readme for more supported runtimes - # gem 'therubyracer', :platform => :ruby + gem 'therubyracer', :platform => :ruby gem 'uglifier', '>= 1.0.3' end diff --git a/Gemfile.lock b/Gemfile.lock index 0f24858..1887036 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,6 +67,7 @@ GEM json (1.7.3) launchy (2.1.0) addressable (~> 2.2.6) + libv8 (3.3.10.4) libwebsocket (0.1.3) addressable mail (2.4.4) @@ -140,6 +141,8 @@ GEM rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.6) + therubyracer (0.10.1) + libv8 (~> 3.3.10) thor (0.14.6) tilt (1.3.3) treetop (1.4.10) @@ -166,4 +169,5 @@ DEPENDENCIES rspec-rails (~> 2.0) sass-rails (~> 3.2.3) sqlite3 + therubyracer uglifier (>= 1.0.3) diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index d13ffd9..6c5be44 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -16,6 +16,7 @@ def index # GET /books/1 # GET /books/1.json def show + @memo = Memo.new respond_to do |format| format.html # show.html.erb format.xml { render xml: @book } diff --git a/app/models/book.rb b/app/models/book.rb index 95c42dd..36ac641 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,6 +1,7 @@ # encoding: UTF-8 class Book < ActiveRecord::Base attr_accessible :memo, :purchased_on, :title + has_many :memos, :dependent => :destroy validates :title, :presence => true before_create :total_books_count diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 23005ab..c25810b 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -15,6 +15,19 @@ <%= @book.purchased_on %>

+
+ Description:
+<% @book.memos.each do |memo| %> + <%= link_to 'Remove', memo, confirm: 'Are you sure?', method: :delete %> +
<%= memo.description %>
+
+
+<% end %> +<%= form_for @memo, :url => book_memos_path(@book) do |f| %> + <%= f.text_area :description %>
+ <%= f.submit %>
+<% end %> +
<%= link_to 'Edit', edit_book_path(@book) %> | <%= link_to 'Back', books_path %> diff --git a/config/routes.rb b/config/routes.rb index f3d38ab..33ad653 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,10 @@ BookMemo2::Application.routes.draw do - resources :books + + resources :memos + resources :books do + resources :memos + end # The priority is based upon order of creation: # first created -> highest priority. diff --git a/db/schema.rb b/db/schema.rb index 5fc61c2..30bf75e 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 => 20120615135737) 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.integer "book_id" + t.text "description" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + end diff --git a/spec/views/books/show.html.erb_spec.rb b/spec/views/books/show.html.erb_spec.rb index 82d0e4b..012b0cc 100644 --- a/spec/views/books/show.html.erb_spec.rb +++ b/spec/views/books/show.html.erb_spec.rb @@ -6,12 +6,13 @@ :title => "Title", :memo => "MyText" )) + @memo = Memo.new end it "renders attributes in

" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - rendered.should match(/Title/) - rendered.should match(/MyText/) + rendered.should match(/Title/) + rendered.should match(/MyText/) end end