Skip to content

Commit b4c3ac2

Browse files
author
saasbook
committed
hw4
1 parent 80d310f commit b4c3ac2

File tree

85 files changed

+4067
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+4067
-4
lines changed

.bundle/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
BUNDLE_WITHOUT: production

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--colour

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ group :development, :test do
1818
gem 'simplecov'
1919
end
2020
group :production do
21-
# gem 'pg'
21+
gem 'pg'
2222
end
2323

2424
# Gems used only for assets and not required

Gemfile.lock

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
actionmailer (3.1.0)
5+
actionpack (= 3.1.0)
6+
mail (~> 2.3.0)
7+
actionpack (3.1.0)
8+
activemodel (= 3.1.0)
9+
activesupport (= 3.1.0)
10+
builder (~> 3.0.0)
11+
erubis (~> 2.7.0)
12+
i18n (~> 0.6)
13+
rack (~> 1.3.2)
14+
rack-cache (~> 1.0.3)
15+
rack-mount (~> 0.8.2)
16+
rack-test (~> 0.6.1)
17+
sprockets (~> 2.0.0)
18+
activemodel (3.1.0)
19+
activesupport (= 3.1.0)
20+
bcrypt-ruby (~> 3.0.0)
21+
builder (~> 3.0.0)
22+
i18n (~> 0.6)
23+
activerecord (3.1.0)
24+
activemodel (= 3.1.0)
25+
activesupport (= 3.1.0)
26+
arel (~> 2.2.1)
27+
tzinfo (~> 0.3.29)
28+
activeresource (3.1.0)
29+
activemodel (= 3.1.0)
30+
activesupport (= 3.1.0)
31+
activesupport (3.1.0)
32+
multi_json (~> 1.0)
33+
addressable (2.2.7)
34+
archive-tar-minitar (0.5.2)
35+
arel (2.2.1)
36+
bcrypt-ruby (3.0.1)
37+
builder (3.0.0)
38+
capybara (1.1.2)
39+
mime-types (>= 1.16)
40+
nokogiri (>= 1.3.3)
41+
rack (>= 1.0.0)
42+
rack-test (>= 0.5.4)
43+
selenium-webdriver (~> 2.0)
44+
xpath (~> 0.1.4)
45+
childprocess (0.3.1)
46+
ffi (~> 1.0.6)
47+
coffee-rails (3.1.1)
48+
coffee-script (>= 2.2.0)
49+
railties (~> 3.1.0)
50+
coffee-script (2.2.0)
51+
coffee-script-source
52+
execjs
53+
coffee-script-source (1.2.0)
54+
columnize (0.3.6)
55+
cucumber (1.1.4)
56+
builder (>= 2.1.2)
57+
diff-lcs (>= 1.1.2)
58+
gherkin (~> 2.7.1)
59+
json (>= 1.4.6)
60+
term-ansicolor (>= 1.0.6)
61+
cucumber-rails (1.2.1)
62+
capybara (>= 1.1.2)
63+
cucumber (>= 1.1.3)
64+
nokogiri (>= 1.5.0)
65+
cucumber-rails-training-wheels (1.0.0)
66+
cucumber-rails (>= 1.1.1)
67+
database_cleaner (0.7.1)
68+
diff-lcs (1.1.3)
69+
erubis (2.7.0)
70+
execjs (1.3.0)
71+
multi_json (~> 1.0)
72+
ffi (1.0.11)
73+
gherkin (2.7.7)
74+
json (>= 1.4.6)
75+
haml (3.1.4)
76+
hike (1.2.1)
77+
i18n (0.6.0)
78+
jquery-rails (1.0.19)
79+
railties (~> 3.0)
80+
thor (~> 0.14)
81+
json (1.6.5)
82+
launchy (2.0.5)
83+
addressable (~> 2.2.6)
84+
libv8 (3.3.10.4)
85+
linecache19 (0.5.12)
86+
ruby_core_source (>= 0.1.4)
87+
mail (2.3.0)
88+
i18n (>= 0.4.0)
89+
mime-types (~> 1.16)
90+
treetop (~> 1.4.8)
91+
mime-types (1.17.2)
92+
multi_json (1.0.4)
93+
nokogiri (1.5.0)
94+
pg (0.12.2)
95+
polyglot (0.3.3)
96+
rack (1.3.6)
97+
rack-cache (1.0.3)
98+
rack (>= 0.4)
99+
rack-mount (0.8.3)
100+
rack (>= 1.0.0)
101+
rack-ssl (1.3.2)
102+
rack
103+
rack-test (0.6.1)
104+
rack (>= 1.0)
105+
rails (3.1.0)
106+
actionmailer (= 3.1.0)
107+
actionpack (= 3.1.0)
108+
activerecord (= 3.1.0)
109+
activeresource (= 3.1.0)
110+
activesupport (= 3.1.0)
111+
bundler (~> 1.0)
112+
railties (= 3.1.0)
113+
railties (3.1.0)
114+
actionpack (= 3.1.0)
115+
activesupport (= 3.1.0)
116+
rack-ssl (~> 1.3.2)
117+
rake (>= 0.8.7)
118+
rdoc (~> 3.4)
119+
thor (~> 0.14.6)
120+
rake (0.9.2.2)
121+
rdoc (3.12)
122+
json (~> 1.4)
123+
rspec (2.8.0)
124+
rspec-core (~> 2.8.0)
125+
rspec-expectations (~> 2.8.0)
126+
rspec-mocks (~> 2.8.0)
127+
rspec-core (2.8.0)
128+
rspec-expectations (2.8.0)
129+
diff-lcs (~> 1.1.2)
130+
rspec-mocks (2.8.0)
131+
rspec-rails (2.8.1)
132+
actionpack (>= 3.0)
133+
activesupport (>= 3.0)
134+
railties (>= 3.0)
135+
rspec (~> 2.8.0)
136+
ruby-debug-base19 (0.11.25)
137+
columnize (>= 0.3.1)
138+
linecache19 (>= 0.5.11)
139+
ruby_core_source (>= 0.1.4)
140+
ruby-debug19 (0.11.6)
141+
columnize (>= 0.3.1)
142+
linecache19 (>= 0.5.11)
143+
ruby-debug-base19 (>= 0.11.19)
144+
ruby_core_source (0.1.5)
145+
archive-tar-minitar (>= 0.5.2)
146+
rubyzip (0.9.6.1)
147+
sass (3.1.15)
148+
sass-rails (3.1.5)
149+
actionpack (~> 3.1.0)
150+
railties (~> 3.1.0)
151+
sass (~> 3.1.10)
152+
tilt (~> 1.3.2)
153+
selenium-webdriver (2.19.0)
154+
childprocess (>= 0.2.5)
155+
ffi (~> 1.0.9)
156+
multi_json (~> 1.0.4)
157+
rubyzip
158+
simplecov (0.5.4)
159+
multi_json (~> 1.0.3)
160+
simplecov-html (~> 0.5.3)
161+
simplecov-html (0.5.3)
162+
sprockets (2.0.3)
163+
hike (~> 1.2)
164+
rack (~> 1.0)
165+
tilt (~> 1.1, != 1.3.0)
166+
sqlite3 (1.3.5)
167+
term-ansicolor (1.0.7)
168+
therubyracer (0.9.9)
169+
libv8 (~> 3.3.10)
170+
thor (0.14.6)
171+
tilt (1.3.3)
172+
treetop (1.4.10)
173+
polyglot
174+
polyglot (>= 0.3.1)
175+
tzinfo (0.3.31)
176+
uglifier (1.2.3)
177+
execjs (>= 0.3.0)
178+
multi_json (>= 1.0.2)
179+
xpath (0.1.4)
180+
nokogiri (~> 1.3)
181+
182+
PLATFORMS
183+
ruby
184+
185+
DEPENDENCIES
186+
capybara
187+
coffee-rails (~> 3.1.0)
188+
cucumber-rails
189+
cucumber-rails-training-wheels
190+
database_cleaner
191+
haml
192+
jquery-rails
193+
launchy
194+
pg
195+
rails (= 3.1.0)
196+
rspec-rails
197+
ruby-debug19
198+
sass-rails (~> 3.1.0)
199+
simplecov
200+
sqlite3
201+
therubyracer
202+
uglifier

app/controllers/movies_controller.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
class MoviesController < ApplicationController
22

33
def show
4-
id = params[:id] # retrieve movie ID from URI route
5-
@movie = Movie.find(id) # look up movie by unique ID
4+
@id = params[:id] # retrieve movie ID from URI route
5+
@movie = Movie.find(@id) # look up movie by unique ID
6+
@director = @movie.director
67
# will render app/views/movies/show.<extension> by default
78
end
89

@@ -57,5 +58,17 @@ def destroy
5758
flash[:notice] = "Movie '#{@movie.title}' deleted."
5859
redirect_to movies_path
5960
end
61+
62+
def similar
63+
@id = params[:movie_id]
64+
@movie = Movie.find(@id)
65+
@director = @movie.director
66+
if not @director.blank?
67+
@movies = Movie.similar_directors(@director)
68+
else
69+
flash[:notice] = "'#{@movie.title}' has no director info"
70+
redirect_to movies_path
71+
end
72+
end
6073

6174
end

app/models/movie.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ class Movie < ActiveRecord::Base
22
def self.all_ratings
33
%w(G PG PG-13 NC-17 R)
44
end
5+
6+
def self.similar_directors(director)
7+
Movie.where(:director => director)
8+
end
59
end

app/views/movies/edit.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212

1313
= label :movie, :release_date, 'Released On'
1414
= date_select :movie, :release_date
15+
16+
= label :movie, :director, 'Director'
17+
= text_field :movie, 'director'
1518

1619
= submit_tag 'Update Movie Info'

app/views/movies/index.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
%th{:class => @title_header}= link_to 'Movie Title', movies_path(:sort => 'title', :ratings => @selected_ratings), :id => 'title_header'
1717
%th Rating
1818
%th{:class => @date_header}= link_to 'Release Date', movies_path(:sort => 'release_date', :ratings => @selected_ratings), :id => 'release_date_header'
19+
%th Director
1920
%th More Info
2021
%tbody
2122
- @movies.each do |movie|
2223
%tr
2324
%td= movie.title
2425
%td= movie.rating
2526
%td= movie.release_date
27+
%td= movie.director
2628
%td= link_to "More about #{movie.title}", movie_path(movie)
2729

2830
= link_to 'Add new movie', new_movie_path

app/views/movies/show.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
%li
1010
Released on:
1111
= @movie.release_date.strftime("%B %d, %Y")
12+
%li
13+
Director:
14+
= @movie.director
1215

1316
%h3 Description:
1417

1518
%p#description= @movie.description
1619

1720
= link_to 'Edit', edit_movie_path(@movie)
1821
= button_to 'Delete', movie_path(@movie), :method => :delete, :confirm => 'Are you sure?'
22+
= link_to 'Find Movies With Same Director', movie_similar_path(@id)
1923
= link_to 'Back to movie list', movies_path

app/views/movies/similar.html.haml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-# in app/views/movies/similar.html.haml
2+
3+
%h2 Movies with Same Director as #{@movie.title}
4+
5+
%table#movies
6+
%thead
7+
%tr
8+
%th Movie Title
9+
%th Rating
10+
%th Release Date
11+
%th Director
12+
%th More Info
13+
%tbody
14+
- @movies.each do |movie|
15+
%tr
16+
%td= movie.title
17+
%td= movie.rating
18+
%td= movie.release_date
19+
%td= movie.director
20+
%td= link_to "More about #{movie.title}", movie_path(movie)
21+
22+
= link_to 'Back', movie_path(@movie)
23+

0 commit comments

Comments
 (0)