diff --git a/.rspec b/.rspec index 89b89ff..9356066 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,3 @@ +--drb --colour ---format=d \ No newline at end of file +--format=d diff --git a/Gemfile b/Gemfile index d643000..692d717 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,11 @@ group :test, :development do gem "rspec-rails", "~> 2.0" gem 'capybara' gem 'launchy' + gem 'guard', '0.10.0' + gem 'guard-rspec' + gem 'guard-spork' + gem 'libnotify' + gem 'rb-inotify' end gem 'pry-rails' gem 'factory_girl_rails' diff --git a/Gemfile.lock b/Gemfile.lock index 0f24858..9a3c56c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,6 +58,14 @@ GEM factory_girl (~> 3.3.0) railties (>= 3.0.0) ffi (1.0.11) + guard (0.10.0) + ffi (>= 0.5.0) + thor (~> 0.14.6) + guard-rspec (0.7.3) + guard (>= 0.10.0) + guard-spork (0.8.0) + guard (>= 0.10.0) + spork (>= 0.8.4) hike (1.2.1) i18n (0.6.0) journey (1.0.3) @@ -67,6 +75,8 @@ GEM json (1.7.3) launchy (2.1.0) addressable (~> 2.2.6) + libnotify (0.7.2) + ffi (~> 1.0.0) libwebsocket (0.1.3) addressable mail (2.4.4) @@ -107,6 +117,8 @@ GEM rdoc (~> 3.4) thor (~> 0.14.6) rake (0.9.2.2) + rb-inotify (0.8.8) + ffi (>= 0.5.0) rdoc (3.12) json (~> 1.4) rspec (2.10.0) @@ -135,6 +147,7 @@ GEM multi_json (~> 1.0) rubyzip slop (2.4.4) + spork (0.9.2) sprockets (2.1.3) hike (~> 1.2) rack (~> 1.0) @@ -159,10 +172,15 @@ DEPENDENCIES capybara coffee-rails (~> 3.2.1) factory_girl_rails + guard (= 0.10.0) + guard-rspec + guard-spork jquery-rails launchy + libnotify pry-rails rails (= 3.2.3) + rb-inotify rspec-rails (~> 2.0) sass-rails (~> 3.2.3) sqlite3 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..e5a04fc --- /dev/null +++ b/Guardfile @@ -0,0 +1,31 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do + watch('config/application.rb') + watch('config/environment.rb') + watch(%r{^config/environments/.+\.rb$}) + watch(%r{^config/initializers/.+\.rb$}) + watch('Gemfile') + watch('Gemfile.lock') + watch('spec/spec_helper.rb') { :rspec } + watch('test/test_helper.rb') { :test_unit } + watch(%r{features/support/}) { :cucumber } +end + +guard 'rspec', :version => 2 do + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } + + # Rails example + watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } + watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } + watch(%r{^spec/support/(.+)\.rb$}) { "spec" } + watch('config/routes.rb') { "spec/routing" } + watch('app/controllers/application_controller.rb') { "spec/controllers" } + # Capybara request specs + watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" } +end + diff --git a/app/assets/javascripts/books.js.coffee b/app/assets/javascripts/books.js.coffee index 7615679..a56ff9c 100644 --- a/app/assets/javascripts/books.js.coffee +++ b/app/assets/javascripts/books.js.coffee @@ -1,3 +1,14 @@ # Place all the behaviors and hooks related to the matching controller here. # All this logic will automatically be available in application.js. # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ + +count = 0 +$("#add-memo").on("click", () -> + $('#memo').append($('
').addClass('field')).append($('').attr({ + 'cols': '40', + 'name': "book[memo_attributes][#{count++}][value]", + 'rows': '5' + })) + return false + +) diff --git a/app/assets/javascripts/memos.js.coffee b/app/assets/javascripts/memos.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/memos.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/memos.css.scss b/app/assets/stylesheets/memos.css.scss new file mode 100644 index 0000000..2b49bc5 --- /dev/null +++ b/app/assets/stylesheets/memos.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the memos controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb new file mode 100644 index 0000000..9842acb --- /dev/null +++ b/app/controllers/memos_controller.rb @@ -0,0 +1,30 @@ +class MemosController < ApplicationController + + # POST /memos + # POST /memos.json + def create + @memo = Memo.new(params[:memo]) + + respond_to do |format| + if @memo.save + #format.html { redirect_to @memo, notice: 'Memo was successfully created.' } + format.json { render json: @memo, status: :created, location: @memo } + else + #format.html { render action: "new" } + format.json { render json: @memo.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /memos/1 + # DELETE /memos/1.json + def destroy + @memo = Memo.find(params[:id]) + @memo.destroy + + respond_to do |format| + #format.html { redirect_to memos_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/memos_helper.rb b/app/helpers/memos_helper.rb new file mode 100644 index 0000000..0e732a1 --- /dev/null +++ b/app/helpers/memos_helper.rb @@ -0,0 +1,2 @@ +module MemosHelper +end diff --git a/app/models/book.rb b/app/models/book.rb index 95c42dd..4605044 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,11 +1,18 @@ # encoding: UTF-8 class Book < ActiveRecord::Base - attr_accessible :memo, :purchased_on, :title + attr_accessible :memo_attributes, :purchased_on, :title, :memo validates :title, :presence => true before_create :total_books_count + has_many :memo, dependent: :destroy + accepts_nested_attributes_for :memo + def total_books_count - self.memo += "【 累計冊数#{Book.count + 1} 】" +=begin + self.memo.each do |m| + m.value += "【 累計冊数#{Book.count + 1} 】" + end +=end end end diff --git a/app/models/memo.rb b/app/models/memo.rb new file mode 100644 index 0000000..572ab8b --- /dev/null +++ b/app/models/memo.rb @@ -0,0 +1,5 @@ +class Memo < ActiveRecord::Base + attr_accessible :value,:book_id + + belongs_to :book +end diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb index da45ee0..701b0e1 100644 --- a/app/views/books/_form.html.erb +++ b/app/views/books/_form.html.erb @@ -15,10 +15,16 @@ <%= f.label :title %>Memo: - <%= @book.memo %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3bed8c4..658b21c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -3,12 +3,12 @@