Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--colour
--format=d
18 changes: 10 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ end

gem 'jquery-rails'

group :test, :development do
gem "rspec-rails", "~> 2.0"
gem 'capybara'
gem 'launchy'
end
gem 'pry-rails'
gem 'factory_girl_rails'
gem 'bootstrap-sass', '2.0.0'
gem "dynamic_form"

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

Expand All @@ -36,11 +46,3 @@ gem 'jquery-rails'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test, :development do
gem "rspec-rails", "~> 2.0"
gem 'capybara'
gem 'launchy'
end
gem 'pry-rails'
gem 'factory_girl_rails'
16 changes: 14 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ GEM
multi_json (~> 1.0)
addressable (2.2.8)
arel (3.0.2)
bootstrap-sass (2.0.0)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
Expand All @@ -49,6 +50,7 @@ GEM
execjs
coffee-script-source (1.3.3)
diff-lcs (1.1.3)
dynamic_form (1.1.4)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
Expand All @@ -75,13 +77,19 @@ GEM
treetop (~> 1.4.8)
method_source (0.7.1)
mime-types (1.18)
multi_json (1.3.5)
multi_json (1.3.6)
nokogiri (1.5.2)
nokogiri (1.5.2-x86-mingw32)
polyglot (0.3.3)
pry (0.9.9.6)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
pry (0.9.9.6-x86-mingw32)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
win32console (~> 1.3)
pry-rails (0.1.6)
pry
rack (1.4.1)
Expand Down Expand Up @@ -140,6 +148,7 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
sqlite3 (1.3.6-x86-mingw32)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
Expand All @@ -149,15 +158,18 @@ GEM
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
win32console (1.3.2-x86-mingw32)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
ruby
x86-mingw32

DEPENDENCIES
bootstrap-sass (= 2.0.0)
capybara
coffee-rails (~> 3.2.1)
dynamic_form
factory_girl_rails
jquery-rails
launchy
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require File.expand_path('../config/application', __FILE__)

BookMemo2::Application.load_tasks
YacBookMemo::Application.load_tasks
3 changes: 3 additions & 0 deletions app/assets/javascripts/memos.js.coffee
Original file line number Diff line number Diff line change
@@ -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/
34 changes: 34 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,37 @@
*= require_self
*= require_tree .
*/

@import "bootstrap";

table
{
border-collapse:collapse;
}

th {
background-color: #AAAAAA;
}

th, td {
border: 1px solid black;
overflow: hidden;
width: 500px;
}

table,th, td
{
table-layout:auto;
border: 1px solid black;
text-align: center;
}


h2 {
font-size: 1.7em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: left;
font-weight: normal;
color: $grayLight;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/memos.css.scss
Original file line number Diff line number Diff line change
@@ -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/
21 changes: 6 additions & 15 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
class BooksController < ApplicationController
before_filter :find_book, :only => [:show, :destroy, :edit, :update]

# GET /books
# GET /books.json
def index
@books = Book.all

respond_to do |format|
format.html # index.html.erb
format.xml { render xml: @books }
format.json { render json: @books }
end
end

# GET /books/1
# GET /books/1.json
def show
@book = Book.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render xml: @book }
format.json { render json: @book }
end
end
Expand All @@ -30,13 +28,13 @@ def new

respond_to do |format|
format.html # new.html.erb
format.xml { render xml: @book }
format.json { render json: @book }
end
end

# GET /books/1/edit
def edit
@book = Book.find(params[:id])
end

# POST /books
Expand All @@ -47,11 +45,9 @@ def create
respond_to do |format|
if @book.save
format.html { redirect_to @book, notice: 'Book was successfully created.' }
format.xml { render xml: @book, status: :created, location: @book }
format.json { render json: @book, status: :created, location: @book }
else
format.html { render action: "new" }
format.xml { render xml: @book.errors, status: :unprocessable_entity }
format.json { render json: @book.errors, status: :unprocessable_entity }
end
end
Expand All @@ -60,14 +56,14 @@ def create
# PUT /books/1
# PUT /books/1.json
def update
@book = Book.find(params[:id])

respond_to do |format|
if @book.update_attributes(params[:book])
format.html { redirect_to @book, notice: 'Book was successfully updated.' }
format.xml { head :no_content }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.xml { render xml: @book.errors, status: :unprocessable_entity }
format.json { render json: @book.errors, status: :unprocessable_entity }
end
end
Expand All @@ -76,17 +72,12 @@ def update
# DELETE /books/1
# DELETE /books/1.json
def destroy
@book = Book.find(params[:id])
@book.destroy

respond_to do |format|
format.html { redirect_to books_url }
format.xml { head :no_content }
format.json { head :no_content }
end
end

private
def find_book
@book = Book.find(params[:id])
end
end
50 changes: 50 additions & 0 deletions app/controllers/memos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class MemosController < ApplicationController


def index
@book = Book.find(params[:book_id])
@memos = @book.memos.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @memos }
end
end

def new
@book = Book.find(params[:book_id])
@memo = @book.memos.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @memo }
end
end

def create
@book = Book.find(params[:book_id])
@memo = @book.memos.new(params[:memo])

respond_to do |format|
if @memo.save
format.html { redirect_to book_memos_path, notice: 'Memo was successfully created.' }
else
format.html { render action: "new" }
end
end


end

def destroy
@book = Book.find(params[:book_id])
@memo = @book.memos.find(params[:id])
@memo.destroy

respond_to do |format|
format.html { redirect_to book_memos_path }
format.json { head :no_content }
end
end

end
2 changes: 2 additions & 0 deletions app/helpers/memos_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MemosHelper
end
14 changes: 6 additions & 8 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# encoding: UTF-8
class Book < ActiveRecord::Base
attr_accessible :memo, :purchased_on, :title
attr_accessible :author, :purchase_date, :title

validates :title, :presence => true

before_create :total_books_count

def total_books_count
self.memo += "【 累計冊数#{Book.count + 1} 】"
end

validates :author, :presence => true

has_many :memos, :dependent => :destroy
end
7 changes: 7 additions & 0 deletions app/models/memo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Memo < ActiveRecord::Base
belongs_to :book
attr_accessible :comment_date, :content, :name

validates :name, :presence => true
validates :content, :presence => true, :length => { :maximum => 100 }
end
8 changes: 4 additions & 4 deletions app/views/books/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :memo %><br />
<%= f.text_area :memo %>
<%= f.label :author %><br />
<%= f.text_field :author %>
</div>
<div class="field">
<%= f.label :purchased_on %><br />
<%= f.date_select :purchased_on %>
<%= f.label :purchase_date %><br />
<%= f.date_select :purchase_date %>
</div>
<div class="actions">
<%= f.submit %>
Expand Down
11 changes: 6 additions & 5 deletions app/views/books/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<table>
<tr>
<th>Title</th>
<th>Memo</th>
<th>Purchased on</th>
<th>Author</th>
<th>Purchase date</th>
<th></th>
<th></th>
<th></th>
Expand All @@ -13,8 +13,8 @@
<% @books.each do |book| %>
<tr>
<td><%= book.title %></td>
<td><%= book.memo %></td>
<td><%= book.purchased_on %></td>
<td><%= book.author %></td>
<td><%= book.purchase_date %></td>
<td><%= link_to 'Show', book %></td>
<td><%= link_to 'Edit', edit_book_path(book) %></td>
<td><%= link_to 'Destroy', book, confirm: 'Are you sure?', method: :delete %></td>
Expand All @@ -24,4 +24,5 @@

<br />

<%= link_to 'New Book', new_book_path %>
<h2><%= link_to 'New Book', new_book_path %></h2>

10 changes: 5 additions & 5 deletions app/views/books/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
</p>

<p>
<b>Memo:</b>
<%= @book.memo %>
<b>Author:</b>
<%= @book.author %>
</p>

<p>
<b>Purchased on:</b>
<%= @book.purchased_on %>
<b>Purchase date:</b>
<%= @book.purchase_date %>
</p>


<%= link_to 'Edit', edit_book_path(@book) %> |
<%= link_to 'View Memos', book_memos_path(@book) %>|
<%= link_to 'Back', books_path %>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>BookMemo2</title>
<title>YacBookMemo</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
Expand Down
Loading