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
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ group :test, :development do
end
gem 'pry-rails'
gem 'factory_girl_rails'
gem 'execjs'
gem 'therubyracer'
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -158,6 +161,7 @@ PLATFORMS
DEPENDENCIES
capybara
coffee-rails (~> 3.2.1)
execjs
factory_girl_rails
jquery-rails
launchy
Expand All @@ -166,4 +170,5 @@ DEPENDENCIES
rspec-rails (~> 2.0)
sass-rails (~> 3.2.3)
sqlite3
therubyracer
uglifier (>= 1.0.3)
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

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

require 'rake'
BookMemo2::Application.load_tasks
3 changes: 3 additions & 0 deletions app/assets/javascripts/memo.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/
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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/memo.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the memo controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
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/
37 changes: 6 additions & 31 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
#coding: utf-8

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
respond_to do |format|
format.html # show.html.erb
format.xml { render xml: @book }
format.json { render json: @book }
end
end

# GET /books/new
# GET /books/new.json
def new
@book = Book.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
Expand All @@ -46,31 +31,21 @@ 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 }
redirect_to @book, :notice => "Completed Registering"
else
format.html { render action: "new" }
format.xml { render xml: @book.errors, status: :unprocessable_entity }
format.json { render json: @book.errors, status: :unprocessable_entity }
render :new
end
end
end

# PUT /books/1
# PUT /books/1.json
def update
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 }
redirect_to @book, :notice =>"Completed Updating"
else
format.html { render action: "edit" }
format.xml { render xml: @book.errors, status: :unprocessable_entity }
format.json { render json: @book.errors, status: :unprocessable_entity }
render :edit
end
end
end

# DELETE /books/1
Expand Down
45 changes: 45 additions & 0 deletions app/controllers/memos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#coding: utf-8

class MemosController < ApplicationController
before_filter :find_book
before_filter :find_memo, :only =>[:edit, :update, :destroy]

def new
@memo = @book.memos.new
end

def create
@memo = @book.memos.new(params[:memo])
if @memo.save
redirect_to book_path(@book), :notice => "Completed Registering Memo."
else
render :new
end
end

def edit
end

def update
if @memo.update_attributes(params[:memo])
redirect_to book_path(@book), :notice => "メモを更新しました。"
else
render :action => "edit"
end
end

def destroy
@memo.destroy
redirect_to book_path(@book)
end

private
def find_book
@book = Book.find(params[:book_id])
end

def find_memo
@memo = @book.memos.find(params[:id])
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
1 change: 1 addition & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding: UTF-8
class Book < ActiveRecord::Base
has_many :memos
attr_accessible :memo, :purchased_on, :title
validates :title, :presence => true

Expand Down
3 changes: 3 additions & 0 deletions app/models/memo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Memo < ActiveRecord::Base
attr_accessible :body, :book_id
end
Binary file added app/views/books/.new.html.erb.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion app/views/books/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>Editing book</h1>

<%= render 'form' %>
<%= render 'form', :book => @book %>

<%= link_to 'Show', @book %> |
<%= link_to 'Back', books_path %>
2 changes: 1 addition & 1 deletion app/views/books/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>New book</h1>

<%= render 'form' %>
<%= render 'form', book => @book %>

<%= link_to 'Back', books_path %>
7 changes: 7 additions & 0 deletions app/views/books/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
<%= @book.purchased_on %>
</p>

<%= link_to 'add memo', new_book_memo_path(@book) %><br/>

<% @book.memos.each do |memo| %>
<%= memo.body %> |
<%= link_to "edit", edit_book_memo_path(:book_id =>@book.id, :id => memo.id) %> |
<%= link_to "delete", book_memo_path(:book_id => @book.id,:id => memo.id), :confirm =>"Are you sure?", :method => :delete %><br/>
<%end%>
<br/>
<%= link_to 'Edit', edit_book_path(@book) %> |
<%= link_to 'Back', books_path %>
8 changes: 8 additions & 0 deletions app/views/memos/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Title:<%= @book.title %><br/>
Memo:<%= @book.memo %><br/>
Parchase Date:<%= @book.purchased_on %><br/>
<br/>
<%= form_for @memo, :url => book_memo_path(:book_id => @book.id, :id => @memo.id), :method => :put do |f| %>
Memo:<%= f.text_field :body %><br/>
<%= f.submit %><br/>
<% end %>
8 changes: 8 additions & 0 deletions app/views/memos/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Title:<%= @book.title %><br/>
Memo:<%= @book.memo %><br/>
Parchase Date:<%= @book.purchased_on %><br/>
<br/>
<%= form_for @memo, :url => book_memos_path do |f| %>
Memo:<%= f.text_field :body %><br/>
<%= f.submit %><br/>
<% end %>
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
BookMemo2::Application.routes.draw do
resources :books

root :to => 'books#index'

resources :books do
resources :memos
end

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/20120617023553_create_memos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateMemos < ActiveRecord::Migration
def change
create_table :memos do |t|
t.integer :book_id
t.text :body

t.timestamps
end
end

def self.down
drop_table :memos
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => 20120617023553) do

create_table "books", :force => true do |t|
t.string "title"
Expand All @@ -21,4 +21,11 @@
t.datetime "updated_at", :null => false
end

create_table "memos", :force => true do |t|
t.integer "book_id"
t.text "body"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

end
Loading