adding base files from rottenpotatoes app

This commit is contained in:
Armando Fox 2015-08-08 19:24:10 -07:00
parent 49bf4c4af6
commit 2d81334803
12 changed files with 229 additions and 0 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@
/log/*
!/log/.keep
/tmp
log

View File

@ -0,0 +1,61 @@
html, body {
margin: 0;
padding: 0;
background: White;
color: DarkSlateGrey;
font-family: Tahoma, Verdana, sans-serif;
font-size: 10pt;
}
div#main {
margin: 0;
padding: 0 20px 20px;
}
a {
background: transparent;
color: maroon;
text-decoration: underline;
font-weight: bold;
}
h1 {
color: maroon;
font-size: 150%;
font-style: italic;
display: block;
width: 100%;
border-bottom: 1px solid DarkSlateGrey;
}
h1.title {
margin: 0 0 1em;
padding: 10px;
background-color: orange;
color: white;
border-bottom: 4px solid gold;
font-size: 2em;
font-style: normal;
}
table#movies {
margin: 10px;
border-collapse: collapse;
width: 100%;
border-bottom: 2px solid black;
}
table#movies th {
border: 2px solid white;
font-weight: bold;
background-color: wheat;
}
table#movies th, table#movies td {
padding: 4px;
text-align: left;
}
#notice #warning {
background: rosybrown;
margin: 1em 0;
padding: 4px;
}
form label {
display: block;
line-height: 25px;
font-weight: bold;
color: maroon;
}

View File

@ -0,0 +1,45 @@
class MoviesController < ApplicationController
def movie_params
params.require(:movie).permit(:title, :rating, :description, :release_date)
end
def show
id = params[:id] # retrieve movie ID from URI route
@movie = Movie.find(id) # look up movie by unique ID
# will render app/views/movies/show.<extension> by default
end
def index
@movies = Movie.all
end
def new
# default: render 'new' template
end
def create
@movie = Movie.create!(movie_params)
flash[:notice] = "#{@movie.title} was successfully created."
redirect_to movies_path
end
def edit
@movie = Movie.find params[:id]
end
def update
@movie = Movie.find params[:id]
@movie.update_attributes!(movie_params)
flash[:notice] = "#{@movie.title} was successfully updated."
redirect_to movie_path(@movie)
end
def destroy
@movie = Movie.find(params[:id])
@movie.destroy
flash[:notice] = "Movie '#{@movie.title}' deleted."
redirect_to movies_path
end
end

View File

@ -0,0 +1,6 @@
module MoviesHelper
# Checks if a number is odd:
def oddness(count)
count.odd? ? "odd" : "even"
end
end

2
app/models/movie.rb Normal file
View File

@ -0,0 +1,2 @@
class Movie < ActiveRecord::Base
end

View File

@ -0,0 +1,17 @@
!!!
%html
%head
%title Rotten Potatoes!
= stylesheet_link_tag 'application', media: 'all', data-turbolinks-track: true
= javascript_include_tag 'application', data-turbolinks-track: true
= csrf_meta_tags
%body
%h1.title Rotten Potatoes!
#main
- if flash[:notice]
#notice.message= flash[:notice]
- elsif flash[:warning]
#warning.message= flash[:warning]
= yield

View File

@ -0,0 +1,16 @@
-# edit.html.haml using partial
%h1 Edit Existing Movie
= form_tag movie_path(@movie), :method => :put do
= label :movie, :title, 'Title'
= text_field :movie, 'title'
= label :movie, :rating, 'Rating'
= select :movie, :rating, ['G','PG','PG-13','R','NC-17']
= label :movie, :release_date, 'Released On'
= date_select :movie, :release_date
= submit_tag 'Update Movie Info'

View File

@ -0,0 +1,19 @@
-# This file is app/views/movies/index.html.haml
%h1 All Movies
%table#movies
%thead
%tr
%th Movie Title
%th Rating
%th Release Date
%th More Info
%tbody
- @movies.each do |movie|
%tr
%td= movie.title
%td= movie.rating
%td= movie.release_date
%td= link_to "More about #{movie.title}", movie_path(movie)
= link_to 'Add new movie', new_movie_path

View File

@ -0,0 +1,14 @@
%h1 Create New Movie
= form_tag movies_path do
= label :movie, :title, 'Title'
= text_field :movie, 'title'
= label :movie, :rating, 'Rating'
= select :movie, :rating, ['G','PG','PG-13','R','NC-17']
= label :movie, :release_date, 'Released On'
= date_select :movie, :release_date
= submit_tag 'Save Changes'

View File

@ -0,0 +1,19 @@
-# in app/views/movies/show.html.haml
%h2 Details about #{@movie.title}
%ul#details
%li
Rating:
= @movie.rating
%li
Released on:
= @movie.release_date.strftime("%B %d, %Y")
%h3 Description:
%p#description= @movie.description
= link_to 'Edit', edit_movie_path(@movie)
= button_to 'Delete', movie_path(@movie), :method => :delete, :confirm => 'Are you sure?'
= link_to 'Back to movie list', movies_path

View File

@ -0,0 +1,13 @@
class CreateMovies < ActiveRecord::Migration
def change
create_table :movies do |t|
t.string :title
t.string :rating
t.text :description
t.datetime :release_date
# Add fields that let Rails automatically keep track
# of when movies are added or modified:
t.timestamps
end
end
end

View File

@ -5,3 +5,19 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
movies = [{:title => 'Aladdin', :rating => 'G', :release_date => '25-Nov-1992'},
{:title => 'The Terminator', :rating => 'R', :release_date => '26-Oct-1984'},
{:title => 'When Harry Met Sally', :rating => 'R', :release_date => '21-Jul-1989'},
{:title => 'The Help', :rating => 'PG-13', :release_date => '10-Aug-2011'},
{:title => 'Chocolat', :rating => 'PG-13', :release_date => '5-Jan-2001'},
{:title => 'Amelie', :rating => 'R', :release_date => '25-Apr-2001'},
{:title => '2001: A Space Odyssey', :rating => 'G', :release_date => '6-Apr-1968'},
{:title => 'The Incredibles', :rating => 'PG', :release_date => '5-Nov-2004'},
{:title => 'Raiders of the Lost Ark', :rating => 'PG', :release_date => '12-Jun-1981'},
{:title => 'Chicken Run', :rating => 'G', :release_date => '21-Jun-2000'},
]
movies.each do |movie|
Movie.create!(movie)
end