From 2d813348035b8d87eb4a30e0b73d8dd1b67abcbe Mon Sep 17 00:00:00 2001 From: Armando Fox Date: Sat, 8 Aug 2015 19:24:10 -0700 Subject: [PATCH] adding base files from rottenpotatoes app --- .gitignore | 1 + app/assets/stylesheets/default.css | 61 ++++++++++++++++++++++ app/controllers/movies_controller.rb | 45 ++++++++++++++++ app/helpers/movies_helper.rb | 6 +++ app/models/movie.rb | 2 + app/views/layouts/application.html.haml | 17 ++++++ app/views/movies/edit.html.haml | 16 ++++++ app/views/movies/index.html.haml | 19 +++++++ app/views/movies/new.html.haml | 14 +++++ app/views/movies/show.html.haml | 19 +++++++ db/migrate/20150809022253_create_movies.rb | 13 +++++ db/seeds.rb | 16 ++++++ 12 files changed, 229 insertions(+) create mode 100644 app/assets/stylesheets/default.css create mode 100644 app/controllers/movies_controller.rb create mode 100644 app/helpers/movies_helper.rb create mode 100644 app/models/movie.rb create mode 100644 app/views/layouts/application.html.haml create mode 100644 app/views/movies/edit.html.haml create mode 100644 app/views/movies/index.html.haml create mode 100644 app/views/movies/new.html.haml create mode 100644 app/views/movies/show.html.haml create mode 100644 db/migrate/20150809022253_create_movies.rb diff --git a/.gitignore b/.gitignore index 050c9d9..cda79f9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ /log/* !/log/.keep /tmp +log diff --git a/app/assets/stylesheets/default.css b/app/assets/stylesheets/default.css new file mode 100644 index 0000000..1963ada --- /dev/null +++ b/app/assets/stylesheets/default.css @@ -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; +} diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 0000000..b63fe4c --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -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. 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 diff --git a/app/helpers/movies_helper.rb b/app/helpers/movies_helper.rb new file mode 100644 index 0000000..f5a1367 --- /dev/null +++ b/app/helpers/movies_helper.rb @@ -0,0 +1,6 @@ +module MoviesHelper + # Checks if a number is odd: + def oddness(count) + count.odd? ? "odd" : "even" + end +end diff --git a/app/models/movie.rb b/app/models/movie.rb new file mode 100644 index 0000000..49198a7 --- /dev/null +++ b/app/models/movie.rb @@ -0,0 +1,2 @@ +class Movie < ActiveRecord::Base +end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 0000000..61369f4 --- /dev/null +++ b/app/views/layouts/application.html.haml @@ -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 diff --git a/app/views/movies/edit.html.haml b/app/views/movies/edit.html.haml new file mode 100644 index 0000000..f9c8db2 --- /dev/null +++ b/app/views/movies/edit.html.haml @@ -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' diff --git a/app/views/movies/index.html.haml b/app/views/movies/index.html.haml new file mode 100644 index 0000000..3bdc477 --- /dev/null +++ b/app/views/movies/index.html.haml @@ -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 diff --git a/app/views/movies/new.html.haml b/app/views/movies/new.html.haml new file mode 100644 index 0000000..2a134a3 --- /dev/null +++ b/app/views/movies/new.html.haml @@ -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' diff --git a/app/views/movies/show.html.haml b/app/views/movies/show.html.haml new file mode 100644 index 0000000..6e9e2a7 --- /dev/null +++ b/app/views/movies/show.html.haml @@ -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 diff --git a/db/migrate/20150809022253_create_movies.rb b/db/migrate/20150809022253_create_movies.rb new file mode 100644 index 0000000..a643f39 --- /dev/null +++ b/db/migrate/20150809022253_create_movies.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..89d4a0b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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