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: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 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 @@ -166,4 +169,5 @@ DEPENDENCIES
rspec-rails (~> 2.0)
sass-rails (~> 3.2.3)
sqlite3
therubyracer
uglifier (>= 1.0.3)
1 change: 1 addition & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions app/views/books/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
<%= @book.purchased_on %>
</p>

<div>
<b>Description:</b><br />
<% @book.memos.each do |memo| %>
<%= link_to 'Remove', memo, confirm: 'Are you sure?', method: :delete %>
<pre><%= memo.description %></pre>
<hr/>
<br />
<% end %>

<%= form_for @memo, :url => book_memos_path(@book) do |f| %>
<%= f.text_area :description %><br />
<%= f.submit %><br />
<% end %>
</div>
<%= link_to 'Edit', edit_book_path(@book) %> |
<%= link_to 'Back', books_path %>
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
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 => 20120615135737) 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 "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

end
5 changes: 3 additions & 2 deletions spec/views/books/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
:title => "Title",
:memo => "MyText"
))
@memo = Memo.new
end

it "renders attributes in <p>" 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