Skip to content

Commit 7c0d5be

Browse files
author
Amanda Ren
committed
hw
1 parent a1b7b64 commit 7c0d5be

Some content is hidden

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

48 files changed

+2466
-0
lines changed

myfolder/app/assets/images/rails.png

6.49 KB
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This is a manifest file that'll be compiled into including all the files listed below.
2+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3+
// be included in the compiled file accessible from http://example.com/assets/application.js
4+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5+
// the compiled file.
6+
//
7+
//= require jquery
8+
//= require jquery_ujs
9+
//= require_tree .
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
html, body {
2+
margin: 0;
3+
padding: 0;
4+
background: White;
5+
color: DarkSlateGrey;
6+
font-family: Tahoma, Verdana, sans-serif;
7+
font-size: 10pt;
8+
}
9+
div#main {
10+
margin: 0;
11+
padding: 0 20px 20px;
12+
}
13+
a {
14+
background: transparent;
15+
color: maroon;
16+
text-decoration: underline;
17+
font-weight: bold;
18+
}
19+
h1 {
20+
color: maroon;
21+
font-size: 150%;
22+
font-style: italic;
23+
display: block;
24+
width: 100%;
25+
border-bottom: 1px solid DarkSlateGrey;
26+
}
27+
h1.title {
28+
margin: 0 0 1em;
29+
padding: 10px;
30+
background-color: orange;
31+
color: white;
32+
border-bottom: 4px solid gold;
33+
font-size: 2em;
34+
font-style: normal;
35+
}
36+
table#movies {
37+
margin: 10px;
38+
border-collapse: collapse;
39+
width: 100%;
40+
border-bottom: 2px solid black;
41+
}
42+
table#movies th {
43+
border: 2px solid white;
44+
font-weight: bold;
45+
background-color: wheat;
46+
}
47+
table#movies th, table#movies td {
48+
padding: 4px;
49+
text-align: left;
50+
}
51+
table#movies th.hilite {
52+
background-color: yellow;
53+
}
54+
#notice #warning {
55+
background: rosybrown;
56+
margin: 1em 0;
57+
padding: 4px;
58+
}
59+
form label {
60+
display: block;
61+
line-height: 25px;
62+
font-weight: bold;
63+
color: maroon;
64+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationController < ActionController::Base
2+
protect_from_forgery
3+
end
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
class MoviesController < ApplicationController
2+
3+
def show
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
7+
# will render app/views/movies/show.<extension> by default
8+
end
9+
10+
def index
11+
sort = params[:sort] || session[:sort]
12+
case sort
13+
when 'title'
14+
ordering,@title_header = {:order => :title}, 'hilite'
15+
when 'release_date'
16+
ordering,@date_header = {:order => :release_date}, 'hilite'
17+
end
18+
@all_ratings = Movie.all_ratings
19+
@selected_ratings = params[:ratings] || session[:ratings] || {}
20+
21+
if params[:sort] != session[:sort]
22+
session[:sort] = sort
23+
redirect_to :sort => sort, :ratings => @selected_ratings and return
24+
end
25+
26+
if params[:ratings] != session[:ratings] and @selected_ratings != {}
27+
session[:sort] = sort
28+
session[:ratings] = @selected_ratings
29+
redirect_to :sort => sort, :ratings => @selected_ratings and return
30+
end
31+
@movies = Movie.find_all_by_rating(@selected_ratings.keys, ordering)
32+
end
33+
34+
def new
35+
# default: render 'new' template
36+
end
37+
38+
def create
39+
@movie = Movie.create!(params[:movie])
40+
flash[:notice] = "#{@movie.title} was successfully created."
41+
redirect_to movies_path
42+
end
43+
44+
def edit
45+
@movie = Movie.find params[:id]
46+
end
47+
48+
def update
49+
@movie = Movie.find params[:id]
50+
@movie.update_attributes!(params[:movie])
51+
flash[:notice] = "#{@movie.title} was successfully updated."
52+
redirect_to movie_path(@movie)
53+
end
54+
55+
def destroy
56+
@movie = Movie.find(params[:id])
57+
@movie.destroy
58+
flash[:notice] = "Movie '#{@movie.title}' deleted."
59+
redirect_to movies_path
60+
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
73+
74+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ApplicationHelper
2+
end

myfolder/app/helpers/movies_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module MoviesHelper
2+
# Checks if a number is odd:
3+
def oddness(count)
4+
count.odd? ? "odd" : "even"
5+
end
6+
end

myfolder/app/mailers/.gitkeep

Whitespace-only changes.

myfolder/app/models/.gitkeep

Whitespace-only changes.

myfolder/app/models/movie.rb

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

0 commit comments

Comments
 (0)