From dbd1e17acc912e7cf9ef7ddff0ae400d18f9cd54 Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 30 Nov 2015 13:42:02 -0800 Subject: [PATCH 01/30] made 3 models - book, movie, album --- Gemfile | 2 +- Gemfile.lock | 6 +++ app/models/album.rb | 2 + app/models/book.rb | 2 + app/models/movie.rb | 2 + db/migrate/20151130213931_create_movies.rb | 12 ++++++ db/migrate/20151130214030_create_books.rb | 12 ++++++ db/migrate/20151130214129_create_albums.rb | 12 ++++++ db/schema.rb | 43 ++++++++++++++++++++++ 9 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 app/models/album.rb create mode 100644 app/models/book.rb create mode 100644 app/models/movie.rb create mode 100644 db/migrate/20151130213931_create_movies.rb create mode 100644 db/migrate/20151130214030_create_books.rb create mode 100644 db/migrate/20151130214129_create_albums.rb create mode 100644 db/schema.rb diff --git a/Gemfile b/Gemfile index db48b77c49..7ddff1f286 100644 --- a/Gemfile +++ b/Gemfile @@ -40,8 +40,8 @@ end group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' + gem 'better_errors' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end - diff --git a/Gemfile.lock b/Gemfile.lock index 90a73de22d..324799af4d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,10 +37,15 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.3) + better_errors (2.1.1) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) builder (3.2.2) byebug (8.2.1) + coderay (1.1.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -139,6 +144,7 @@ PLATFORMS ruby DEPENDENCIES + better_errors byebug coffee-rails (~> 4.1.0) jbuilder (~> 2.0) diff --git a/app/models/album.rb b/app/models/album.rb new file mode 100644 index 0000000000..46fa309e4e --- /dev/null +++ b/app/models/album.rb @@ -0,0 +1,2 @@ +class Album < ActiveRecord::Base +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000000..6f68b44465 --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,2 @@ +class Book < ActiveRecord::Base +end diff --git a/app/models/movie.rb b/app/models/movie.rb new file mode 100644 index 0000000000..49198a7d97 --- /dev/null +++ b/app/models/movie.rb @@ -0,0 +1,2 @@ +class Movie < ActiveRecord::Base +end diff --git a/db/migrate/20151130213931_create_movies.rb b/db/migrate/20151130213931_create_movies.rb new file mode 100644 index 0000000000..1c40a5f879 --- /dev/null +++ b/db/migrate/20151130213931_create_movies.rb @@ -0,0 +1,12 @@ +class CreateMovies < ActiveRecord::Migration + def change + create_table :movies do |t| + t.string :name + t.string :director + t.string :description + t.integer :rank + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151130214030_create_books.rb b/db/migrate/20151130214030_create_books.rb new file mode 100644 index 0000000000..12eb4ee8b2 --- /dev/null +++ b/db/migrate/20151130214030_create_books.rb @@ -0,0 +1,12 @@ +class CreateBooks < ActiveRecord::Migration + def change + create_table :books do |t| + t.string :name + t.string :author + t.string :description + t.integer :rank + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20151130214129_create_albums.rb b/db/migrate/20151130214129_create_albums.rb new file mode 100644 index 0000000000..9f04354899 --- /dev/null +++ b/db/migrate/20151130214129_create_albums.rb @@ -0,0 +1,12 @@ +class CreateAlbums < ActiveRecord::Migration + def change + create_table :albums do |t| + t.string :name + t.string :artist + t.string :description + t.integer :rank + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..03b696d4a0 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,43 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20151130214129) do + + create_table "albums", force: :cascade do |t| + t.string "name" + t.string "artist" + t.string "description" + t.integer "rank" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "books", force: :cascade do |t| + t.string "name" + t.string "author" + t.string "description" + t.integer "rank" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "movies", force: :cascade do |t| + t.string "name" + t.string "director" + t.string "description" + t.integer "rank" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end From f2135a61ef977daa4890e3bf926ac9ead7e3fa9a Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 30 Nov 2015 13:44:00 -0800 Subject: [PATCH 02/30] created 4 new controller - 1 for welcome --- app/assets/javascripts/albums.coffee | 3 +++ app/assets/javascripts/books.coffee | 3 +++ app/assets/javascripts/movies.coffee | 3 +++ app/assets/javascripts/welcome.coffee | 3 +++ app/assets/stylesheets/albums.scss | 3 +++ app/assets/stylesheets/books.scss | 3 +++ app/assets/stylesheets/movies.scss | 3 +++ app/assets/stylesheets/welcome.scss | 3 +++ app/controllers/albums_controller.rb | 2 ++ app/controllers/books_controller.rb | 2 ++ app/controllers/movies_controller.rb | 2 ++ app/controllers/welcome_controller.rb | 2 ++ app/helpers/albums_helper.rb | 2 ++ app/helpers/books_helper.rb | 2 ++ app/helpers/movies_helper.rb | 2 ++ app/helpers/welcome_helper.rb | 2 ++ 16 files changed, 40 insertions(+) create mode 100644 app/assets/javascripts/albums.coffee create mode 100644 app/assets/javascripts/books.coffee create mode 100644 app/assets/javascripts/movies.coffee create mode 100644 app/assets/javascripts/welcome.coffee create mode 100644 app/assets/stylesheets/albums.scss create mode 100644 app/assets/stylesheets/books.scss create mode 100644 app/assets/stylesheets/movies.scss create mode 100644 app/assets/stylesheets/welcome.scss create mode 100644 app/controllers/albums_controller.rb create mode 100644 app/controllers/books_controller.rb create mode 100644 app/controllers/movies_controller.rb create mode 100644 app/controllers/welcome_controller.rb create mode 100644 app/helpers/albums_helper.rb create mode 100644 app/helpers/books_helper.rb create mode 100644 app/helpers/movies_helper.rb create mode 100644 app/helpers/welcome_helper.rb diff --git a/app/assets/javascripts/albums.coffee b/app/assets/javascripts/albums.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/albums.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/books.coffee b/app/assets/javascripts/books.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/books.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/movies.coffee b/app/assets/javascripts/movies.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/movies.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/welcome.coffee b/app/assets/javascripts/welcome.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/welcome.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/albums.scss b/app/assets/stylesheets/albums.scss new file mode 100644 index 0000000000..0eb33ca0f6 --- /dev/null +++ b/app/assets/stylesheets/albums.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the albums controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/books.scss b/app/assets/stylesheets/books.scss new file mode 100644 index 0000000000..81379d103f --- /dev/null +++ b/app/assets/stylesheets/books.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the books controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/movies.scss b/app/assets/stylesheets/movies.scss new file mode 100644 index 0000000000..70aaa8a9a4 --- /dev/null +++ b/app/assets/stylesheets/movies.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the movies controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/welcome.scss b/app/assets/stylesheets/welcome.scss new file mode 100644 index 0000000000..77ce11a740 --- /dev/null +++ b/app/assets/stylesheets/welcome.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the welcome controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb new file mode 100644 index 0000000000..2f800bd33f --- /dev/null +++ b/app/controllers/albums_controller.rb @@ -0,0 +1,2 @@ +class AlbumsController < ApplicationController +end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000000..cdb437b99f --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,2 @@ +class BooksController < ApplicationController +end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 0000000000..6c4c516140 --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,2 @@ +class MoviesController < ApplicationController +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 0000000000..d8c85ab84b --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,2 @@ +class WelcomeController < ApplicationController +end diff --git a/app/helpers/albums_helper.rb b/app/helpers/albums_helper.rb new file mode 100644 index 0000000000..d976b7cef8 --- /dev/null +++ b/app/helpers/albums_helper.rb @@ -0,0 +1,2 @@ +module AlbumsHelper +end diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000000..4b9311e0be --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/helpers/movies_helper.rb b/app/helpers/movies_helper.rb new file mode 100644 index 0000000000..493eee555f --- /dev/null +++ b/app/helpers/movies_helper.rb @@ -0,0 +1,2 @@ +module MoviesHelper +end diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb new file mode 100644 index 0000000000..eeead45fc9 --- /dev/null +++ b/app/helpers/welcome_helper.rb @@ -0,0 +1,2 @@ +module WelcomeHelper +end From ab36e37fbdfc34ff33014fa25cf48a2cd95a20a1 Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 30 Nov 2015 14:03:19 -0800 Subject: [PATCH 03/30] made home page --- app/controllers/welcome_controller.rb | 4 ++++ app/views/welcome/index.html.erb | 17 +++++++++++++++++ config/routes.rb | 13 +++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 app/views/welcome/index.html.erb diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index d8c85ab84b..7706bcfedb 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,2 +1,6 @@ class WelcomeController < ApplicationController + + def index + end + end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb new file mode 100644 index 0000000000..cd3c0de60f --- /dev/null +++ b/app/views/welcome/index.html.erb @@ -0,0 +1,17 @@ +
+

Top Movies

+ + <%= link_to "View more albums", movies_path %> +
+ +
+

Top Books

+ + <%= link_to "View more books", books_path %> +
+ +
+

Top Albums

+ + <%= link_to "View more albums", albums_path %> +
diff --git a/config/routes.rb b/config/routes.rb index 3f66539d54..e541c0d331 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,17 @@ Rails.application.routes.draw do + + root to: 'welcome#index' + + resources :books do + end + + resources :albums do + + end + + resources :movies do + + end # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". From 61e4358ab2427bba9095e6484fbd399dd1cb76de Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 30 Nov 2015 14:09:19 -0800 Subject: [PATCH 04/30] made routes and actions in the controllers --- app/controllers/albums_controller.rb | 25 +++++++++++++++++++++++++ app/controllers/books_controller.rb | 25 +++++++++++++++++++++++++ app/controllers/movies_controller.rb | 24 ++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 2f800bd33f..025035a4a5 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,2 +1,27 @@ class AlbumsController < ApplicationController + + def index + end + + def new + end + + def show + end + + def update + end + + def create + end + + def destroy + end + + private + + def album_params + params.permit(:album[:name, :artist, :description]) + end + end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index cdb437b99f..71392218ab 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,2 +1,27 @@ class BooksController < ApplicationController + + def index + end + + def new + end + + def show + end + + def update + end + + def create + end + + def destroy + end + + private + + def book_params + params.permit(:book[:name, :author, :description]) + end + end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 6c4c516140..8354da4b6c 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,2 +1,26 @@ class MoviesController < ApplicationController + + def index + end + + def new + end + + def show + end + + def update + end + + def create + end + + def destroy + end + + private + + def movie_params + params.permit(:movie[:name, :director, :description]) + end end From 61e33ff08bbfac8eec50b1c2916c3c5c3a17fc67 Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 30 Nov 2015 15:22:02 -0800 Subject: [PATCH 05/30] created some seed --- app/controllers/albums_controller.rb | 16 +++++++++++++++ app/controllers/books_controller.rb | 5 +++++ app/controllers/movies_controller.rb | 5 +++++ app/controllers/welcome_controller.rb | 5 ++++- app/views/albums/_form.html.erb | 11 ++++++++++ app/views/albums/edit.html.erb | 2 ++ app/views/albums/index.html.erb | 5 +++++ app/views/albums/new.html.erb | 2 ++ app/views/albums/show.html.erb | 7 +++++++ app/views/books/index.html.erb | 0 app/views/books/show.html.erb | 0 app/views/layouts/application.html.erb | 3 +++ app/views/movies/index.html.erb | 0 app/views/movies/show.html.erb | 0 app/views/welcome/index.html.erb | 21 +++++++++++++------ db/seeds.rb | 28 ++++++++++++++++++++++++++ 16 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 app/views/albums/_form.html.erb create mode 100644 app/views/albums/edit.html.erb create mode 100644 app/views/albums/index.html.erb create mode 100644 app/views/albums/new.html.erb create mode 100644 app/views/albums/show.html.erb create mode 100644 app/views/books/index.html.erb create mode 100644 app/views/books/show.html.erb create mode 100644 app/views/movies/index.html.erb create mode 100644 app/views/movies/show.html.erb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 025035a4a5..0e4395f940 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,18 +1,34 @@ class AlbumsController < ApplicationController + def get_album + @album = Album.find(params[:album_id]) + end + def index end def new + @album = Album.new end def show + get_album end def update + if params[:value] == "upvote" + get_album + rank = @album[:rank] + 1 + @album.update(:rank => rank) + render "show" + else + get_album + @album.update(album_params[:album]) + end end def create + end def destroy diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 71392218ab..75387b4b10 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,5 +1,9 @@ class BooksController < ApplicationController + def get_book + @book = Book.find(params[:book_id]) + end + def index end @@ -7,6 +11,7 @@ def new end def show + get_book end def update diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 8354da4b6c..c2fe0d02b9 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,5 +1,9 @@ class MoviesController < ApplicationController + def get_movie + @movie = Movie.find(params[:movie_id]) + end + def index end @@ -7,6 +11,7 @@ def new end def show + get_movie end def update diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 7706bcfedb..6f0e66598b 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,6 +1,9 @@ class WelcomeController < ApplicationController def index + @movies = Movie.all + @albums = Album.all + @books = Book.all end - + end diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb new file mode 100644 index 0000000000..43128cd8c8 --- /dev/null +++ b/app/views/albums/_form.html.erb @@ -0,0 +1,11 @@ +<%= form_for @album do |f| %> + <%= f.label :Name %>: + <%= f.text_field :name, :required => true %> +
+ <%= f.label :Artist %>: + <%= f.text_field :artist, :required => true %> +
+ <%= f.label :Description %>: + <%= f.text_field :description %> +
+ <%= @album.persisted? ? (f.submit value: "Update album", id: 'special-button') : (f.submit value: "Add album", id: 'special-button') %> diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb new file mode 100644 index 0000000000..2bfe64869d --- /dev/null +++ b/app/views/albums/edit.html.erb @@ -0,0 +1,2 @@ +

Edit Album

+<%= reder "form" %> diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb new file mode 100644 index 0000000000..d20da51894 --- /dev/null +++ b/app/views/albums/index.html.erb @@ -0,0 +1,5 @@ +

<<%= album.name %> Recorded By: <%= album.artist %>

+

Ranked: <%= album.rank %>

+

<%= album.description %>

+ +<%= button_to "Upvote", action: "patch", value:"upvote" %> diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb new file mode 100644 index 0000000000..6560c0b2b1 --- /dev/null +++ b/app/views/albums/new.html.erb @@ -0,0 +1,2 @@ +

Add Album

+<%= render "form" %> diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb new file mode 100644 index 0000000000..f8a5299138 --- /dev/null +++ b/app/views/albums/show.html.erb @@ -0,0 +1,7 @@ +

<<%= @album.name %> Recorded By: <%= @album.artist %>

+

Ranked: <%= @album.rank %>

+

<%= @album.description %>

+ +<%= button_to "Upvote", action: "update", value:"upvote" %> +<%= button_to "Edit" , action: "edit" %> +<%= button 'Delete', {action: "delete", id: @album.id}, method: :delete, data: { confirm: 'Are you sure?' } %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2d02e8fbd4..5a2e5f080c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,6 +5,9 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> + +

<%=link_to "Media Ranker", root_path %> Ranking the Best of Everything

+ diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index cd3c0de60f..1ecc6785ea 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -1,17 +1,26 @@
-

Top Movies

- +

Top Movies

+ <% @movies.each do |movie| %> + <%= link_to movie.name, movie_path %> Ranked: <%= movie.rank %> + <% end %> +
<%= link_to "View more albums", movies_path %>
-

Top Books

- +

Top Books

+ <% @books.each do |book| %> + <%= link_to book.name, book_path %> Ranked: <%= book.rank %> + <% end %> +
<%= link_to "View more books", books_path %>
-

Top Albums

- +

Top Albums

+ <% @albums.each do |album| %> + <%= link_to album.name, album_path %> Ranked: <%= album.rank %> + <% end %> +
<%= link_to "View more albums", albums_path %>
diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e857e..165985493b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,31 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +seed_movie = [ + {name: "movie1", director: "boobli", description: "accountant", rank: 4}, + {name: "movie2", director: "32", description: "actor", rank: 5}, + {name: "movie3", director: "dddd", description: "actor", rank: 3} +] + +seed_movie.each do |movie| + Movie.create(movie) +end + +seed_book = [ + {name: "book1", author: "boodbli", description: "accountant", rank: 2}, + {name: "book2", author: "bosaobli", description: "actor", rank: 6}, + {name: "book3", author: "bosobli", description: "actor", rank: 10} +] +seed_book.each do |book| + Book.create(book) +end + +seed_album = [ + {name: "album1", artist: "booXXbli", description: "accountant", rank: 5}, + {name: "album2", artist: "S", description: "actor", rank: 4}, + {name: "album4", artist: "boobli", description: "actor", rank: 3} +] + +seed_album.each do |album| + Album.create(album) +end From aa71225abb67f0ffbe39c3980355db50ad0e74d9 Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 30 Nov 2015 15:54:58 -0800 Subject: [PATCH 06/30] i MADE AN EDIT BUTTON --- app/controllers/albums_controller.rb | 6 +++++- app/views/albums/_form.html.erb | 1 + app/views/albums/edit.html.erb | 2 +- app/views/albums/show.html.erb | 3 +-- app/views/welcome/index.html.erb | 6 +++--- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 0e4395f940..4e68e4025e 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,7 +1,7 @@ class AlbumsController < ApplicationController def get_album - @album = Album.find(params[:album_id]) + @album = Album.find(params[:id]) end def index @@ -11,6 +11,10 @@ def new @album = Album.new end + def edit + get_album + end + def show get_album end diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb index 43128cd8c8..c0314c885c 100644 --- a/app/views/albums/_form.html.erb +++ b/app/views/albums/_form.html.erb @@ -9,3 +9,4 @@ <%= f.text_field :description %>
<%= @album.persisted? ? (f.submit value: "Update album", id: 'special-button') : (f.submit value: "Add album", id: 'special-button') %> +<% end %> diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb index 2bfe64869d..ab312ab09a 100644 --- a/app/views/albums/edit.html.erb +++ b/app/views/albums/edit.html.erb @@ -1,2 +1,2 @@

Edit Album

-<%= reder "form" %> +<%= render "form" %> diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index f8a5299138..00259180d1 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -3,5 +3,4 @@

<%= @album.description %>

<%= button_to "Upvote", action: "update", value:"upvote" %> -<%= button_to "Edit" , action: "edit" %> -<%= button 'Delete', {action: "delete", id: @album.id}, method: :delete, data: { confirm: 'Are you sure?' } %> +<%= button_to "Edit", { action: "edit", id: @album.id }, method: :get %> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 1ecc6785ea..60966da6a0 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -1,7 +1,7 @@

Top Movies

<% @movies.each do |movie| %> - <%= link_to movie.name, movie_path %> Ranked: <%= movie.rank %> +
  • <%= link_to movie.name, movie_path(movie.id) %> Ranked: <%= movie.rank %>
  • <% end %>
    <%= link_to "View more albums", movies_path %> @@ -10,7 +10,7 @@

    Top Books

    <% @books.each do |book| %> - <%= link_to book.name, book_path %> Ranked: <%= book.rank %> +
  • <%= link_to book.name, book_path(book.id) %> Ranked: <%= book.rank %>
  • <% end %>
    <%= link_to "View more books", books_path %> @@ -19,7 +19,7 @@

    Top Albums

    <% @albums.each do |album| %> - <%= link_to album.name, album_path %> Ranked: <%= album.rank %> +
  • <%= link_to album.name, album_path(album.id) %> Ranked: <%= album.rank %>
  • <% end %>
    <%= link_to "View more albums", albums_path %> From 72475cfc1b353150d78f89543c903d9458e2e75b Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 30 Nov 2015 16:26:13 -0800 Subject: [PATCH 07/30] made new links for albums --- app/controllers/albums_controller.rb | 4 +++- app/views/albums/index.html.erb | 6 +----- app/views/albums/show.html.erb | 5 ++++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 4e68e4025e..1d4fdaa2e9 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -28,9 +28,11 @@ def update else get_album @album.update(album_params[:album]) + redirect_to album_path end end + def create end @@ -41,7 +43,7 @@ def destroy private def album_params - params.permit(:album[:name, :artist, :description]) + params.permit(album: [:name, :artist, :description, :rank]) end end diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index d20da51894..14125b7157 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -1,5 +1 @@ -

    <<%= album.name %> Recorded By: <%= album.artist %>

    -

    Ranked: <%= album.rank %>

    -

    <%= album.description %>

    - -<%= button_to "Upvote", action: "patch", value:"upvote" %> + Ranking diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index 00259180d1..ab3f6cac3f 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -2,5 +2,8 @@

    Ranked: <%= @album.rank %>

    <%= @album.description %>

    -<%= button_to "Upvote", action: "update", value:"upvote" %> + <%= button_to "Edit", { action: "edit", id: @album.id }, method: :get %> +<%= button_to "Delete", action: "destroy", id: @album.id %> +<%= button_to "View all movies", movies_path, method: :get%> +<%= button_to "View all media", root_path, method: :get %> From 998cc26d6831dc7f581303d977e3ad5d49f34533 Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 30 Nov 2015 16:41:21 -0800 Subject: [PATCH 08/30] the upvote is working... whhhhoooo --- app/controllers/albums_controller.rb | 2 +- app/views/albums/index.html.erb | 6 +++++- app/views/albums/show.html.erb | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 1d4fdaa2e9..08c1ffdb57 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -20,7 +20,7 @@ def show end def update - if params[:value] == "upvote" + if params[:class] == "upvote" get_album rank = @album[:rank] + 1 @album.update(:rank => rank) diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index 14125b7157..d333c9d83d 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -1 +1,5 @@ - Ranking + + + + +
    Ranking Name Upvote
    diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index ab3f6cac3f..e53b504ce0 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -2,8 +2,8 @@

    Ranked: <%= @album.rank %>

    <%= @album.description %>

    - +<%= button_to "Upvote", { action: "update" , class: "upvote"}, method: "patch"%> <%= button_to "Edit", { action: "edit", id: @album.id }, method: :get %> <%= button_to "Delete", action: "destroy", id: @album.id %> -<%= button_to "View all movies", movies_path, method: :get%> +<%= button_to "View all albums", albums_path, method: :get%> <%= button_to "View all media", root_path, method: :get %> From b11a52283b1adfb8db96bce44d1d89145912aa25 Mon Sep 17 00:00:00 2001 From: Tammy Date: Mon, 30 Nov 2015 16:51:21 -0800 Subject: [PATCH 09/30] made an index page for albums --- app/controllers/albums_controller.rb | 1 + app/views/albums/index.html.erb | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index 08c1ffdb57..a5d7067cff 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -5,6 +5,7 @@ def get_album end def index + @albums = Album.all end def new diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index d333c9d83d..5a1c50edb6 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -1,5 +1,12 @@ - - + + + <% @albums.each do |album| %> + + + + + + <% end %>
    Ranking Name RankingName Upvote
    Ranked: <%= album.rank %> <%= album.name %> <%= button_to "Upvote", { action: "update" , class: "upvote", id: album.id}, method: "patch" %>
    From da7e1e15a390d172c2e069f28def85d6de6f58ee Mon Sep 17 00:00:00 2001 From: Tammy Date: Tue, 1 Dec 2015 07:57:23 -0800 Subject: [PATCH 10/30] completed views and controller for movies (exapt delete) --- app/controllers/books_controller.rb | 20 ++++++++++++++++++-- app/views/books/_form.html.erb | 12 ++++++++++++ app/views/books/edit.html.erb | 2 ++ app/views/books/index.html.erb | 12 ++++++++++++ app/views/books/new.html.erb | 2 ++ app/views/books/show.html.erb | 9 +++++++++ 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 app/views/books/_form.html.erb create mode 100644 app/views/books/edit.html.erb create mode 100644 app/views/books/new.html.erb diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 75387b4b10..41d48e1202 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,13 +1,19 @@ class BooksController < ApplicationController def get_book - @book = Book.find(params[:book_id]) + @book = Book.find(params[:id]) end def index + @books = Book.all end def new + @album = Album.new + end + + def edit + get_book end def show @@ -15,6 +21,16 @@ def show end def update + if params[:class] == "upvote" + get_book + rank = @book[:rank] + 1 + @book.update(:rank => rank) + render "show" + else + get_book + @book.update(book_params[:book]) + redirect_to book_path + end end def create @@ -26,7 +42,7 @@ def destroy private def book_params - params.permit(:book[:name, :author, :description]) + params.permit(book: [:name, :author, :description, :rank]) end end diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb new file mode 100644 index 0000000000..8ecdfd7c20 --- /dev/null +++ b/app/views/books/_form.html.erb @@ -0,0 +1,12 @@ +<%= form_for @book do |f| %> + <%= f.label :Name %>: + <%= f.text_field :name, :required => true %> +
    + <%= f.label :Author %>: + <%= f.text_field :author, :required => true %> +
    + <%= f.label :Description %>: + <%= f.text_field :description %> +
    + <%= @book.persisted? ? (f.submit value: "Update book", id: 'special-button') : (f.submit value: "Add book", id: 'special-button') %> +<% end %> diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb new file mode 100644 index 0000000000..63c316fec2 --- /dev/null +++ b/app/views/books/edit.html.erb @@ -0,0 +1,2 @@ +

    Edit a book

    +<%= render "form" %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index e69de29bb2..fa6103f366 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -0,0 +1,12 @@ + + + + + <% @books.each do |book| %> + + + + + + <% end %> +
    RankingName Upvote
    Ranked: <%= book.rank %> <%= book.name %> <%= button_to "Upvote", { action: "update" , class: "upvote", id: book.id}, method: "patch" %>
    diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb new file mode 100644 index 0000000000..214eff872e --- /dev/null +++ b/app/views/books/new.html.erb @@ -0,0 +1,2 @@ +

    Add a book

    +<%= render "form" %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index e69de29bb2..45a75c360c 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -0,0 +1,9 @@ +

    <<%= @book.name %> Recorded By: <%= @book.author %>

    +

    Ranked: <%= @book.rank %>

    +

    <%= @book.description %>

    + +<%= button_to "Upvote", { action: "update" , class: "upvote"}, method: "patch"%> +<%= button_to "Edit", { action: "edit", id: @book.id }, method: :get %> +<%= button_to "Delete", action: "destroy", id: @book.id %> +<%= button_to "View all books", albums_path, method: :get%> +<%= button_to "View all media", root_path, method: :get %> From babed9150540e94b215c044489a53e84862903d7 Mon Sep 17 00:00:00 2001 From: Tammy Date: Tue, 1 Dec 2015 08:04:24 -0800 Subject: [PATCH 11/30] completed 3 models most view and controllers --- app/controllers/movies_controller.rb | 20 ++++++++++++++++++-- app/views/movies/_form.html.erb | 12 ++++++++++++ app/views/movies/edit.html.erb | 2 ++ app/views/movies/index.html.erb | 12 ++++++++++++ app/views/movies/new.html.erb | 2 ++ app/views/movies/show.html.erb | 9 +++++++++ 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 app/views/movies/_form.html.erb create mode 100644 app/views/movies/edit.html.erb create mode 100644 app/views/movies/new.html.erb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index c2fe0d02b9..dd07ee4bb2 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -1,20 +1,36 @@ class MoviesController < ApplicationController def get_movie - @movie = Movie.find(params[:movie_id]) + @movie = Movie.find(params[:id]) end def index + @movies = Movie.all end def new + @movie = Movie.new end def show get_movie end + def edit + get_movie + end + def update + if params[:class] == "upvote" + get_movie + rank = @movie[:rank] + 1 + @movie.update(:rank => rank) + render "show" + else + get_movie + @movie.update(movie_params[:movie]) + redirect_to movie_path + end end def create @@ -26,6 +42,6 @@ def destroy private def movie_params - params.permit(:movie[:name, :director, :description]) + params.permit(movie: [:name, :director, :description, :rank]) end end diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb new file mode 100644 index 0000000000..dd2fbd4966 --- /dev/null +++ b/app/views/movies/_form.html.erb @@ -0,0 +1,12 @@ +<%= form_for @movie do |f| %> + <%= f.label :Name %>: + <%= f.text_field :name, :required => true %> +
    + <%= f.label :Director %>: + <%= f.text_field :director, :required => true %> +
    + <%= f.label :Description %>: + <%= f.text_field :description %> +
    + <%= @movie.persisted? ? (f.submit value: "Update movie", id: 'special-button') : (f.submit value: "Add movie", id: 'special-button') %> +<% end %> diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb new file mode 100644 index 0000000000..f8c3a08ed0 --- /dev/null +++ b/app/views/movies/edit.html.erb @@ -0,0 +1,2 @@ +

    Edit a movie

    +<%= render "form" %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index e69de29bb2..b5a188a936 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -0,0 +1,12 @@ + + + + + <% @movies.each do |movie| %> + + + + + + <% end %> +
    RankingName Upvote
    Ranked: <%= movie.rank %> <%= movie.name %> <%= button_to "Upvote", { action: "update" , class: "upvote", id: movie.id}, method: "patch" %>
    diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb new file mode 100644 index 0000000000..bfd1bdd238 --- /dev/null +++ b/app/views/movies/new.html.erb @@ -0,0 +1,2 @@ +

    Add a movie

    +<%= render "form" %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index e69de29bb2..f6e06e0d7c 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -0,0 +1,9 @@ +

    <<%= @movie.name %> Recorded By: <%= @movie.director %>

    +

    Ranked: <%= @movie.rank %>

    +

    <%= @movie.description %>

    + +<%= button_to "Upvote", { action: "update" , class: "upvote"}, method: "patch"%> +<%= button_to "Edit", { action: "edit", id: @movie.id }, method: :get %> +<%= button_to "Delete", action: "destroy", id: @movie.id %> +<%= button_to "View all movies", albums_path, method: :get%> +<%= button_to "View all media", root_path, method: :get %> From e68f8806cc7e7b07f39e4d5b8e549a4093a4818a Mon Sep 17 00:00:00 2001 From: Tammy Date: Tue, 1 Dec 2015 13:41:29 -0800 Subject: [PATCH 12/30] made link to movie's name --- .rspec | 2 + Gemfile | 1 + Gemfile.lock | 19 +++++ app/controllers/albums_controller.rb | 3 +- app/controllers/books_controller.rb | 2 + app/controllers/movies_controller.rb | 2 + app/models/album.rb | 1 + app/models/book.rb | 1 + app/models/movie.rb | 1 + app/views/movies/index.html.erb | 2 +- app/views/movies/show.html.erb | 2 +- spec/controllers/albums_controller_spec.rb | 10 +++ spec/controllers/books_controller_spec.rb | 10 +++ spec/controllers/movies_controller_spec.rb | 10 +++ spec/helpers/albums_helper_spec.rb | 15 ++++ spec/helpers/books_helper_spec.rb | 15 ++++ spec/helpers/movies_helper_spec.rb | 15 ++++ spec/models/album_spec.rb | 23 ++++++ spec/models/book_spec.rb | 23 ++++++ spec/models/movie_spec.rb | 22 ++++++ spec/rails_helper.rb | 57 ++++++++++++++ spec/spec_helper.rb | 92 ++++++++++++++++++++++ 22 files changed, 325 insertions(+), 3 deletions(-) create mode 100644 .rspec create mode 100644 spec/controllers/albums_controller_spec.rb create mode 100644 spec/controllers/books_controller_spec.rb create mode 100644 spec/controllers/movies_controller_spec.rb create mode 100644 spec/helpers/albums_helper_spec.rb create mode 100644 spec/helpers/books_helper_spec.rb create mode 100644 spec/helpers/movies_helper_spec.rb create mode 100644 spec/models/album_spec.rb create mode 100644 spec/models/book_spec.rb create mode 100644 spec/models/movie_spec.rb create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000000..83e16f8044 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/Gemfile b/Gemfile index 7ddff1f286..f0cfccafd1 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,7 @@ group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' gem 'better_errors' + gem 'rspec-rails' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' diff --git a/Gemfile.lock b/Gemfile.lock index 324799af4d..ae4cd69fe7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -54,6 +54,7 @@ GEM execjs coffee-script-source (1.10.0) debug_inspector (0.0.2) + diff-lcs (1.2.5) erubis (2.7.0) execjs (2.6.0) globalid (0.3.6) @@ -106,6 +107,23 @@ GEM thor (>= 0.18.1, < 2.0) rake (10.4.2) rdoc (4.2.0) + rspec-core (3.4.1) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-rails (3.4.0) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) sass (3.4.19) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -150,6 +168,7 @@ DEPENDENCIES jbuilder (~> 2.0) jquery-rails rails (= 4.2.5) + rspec-rails sass-rails (~> 5.0) sdoc (~> 0.4.0) spring diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index a5d7067cff..c20d80ca22 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -35,7 +35,8 @@ def update def create - + Album.create(album_params[:album]) + redirect_to show_path end def destroy diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 41d48e1202..5cb83a3962 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -34,6 +34,8 @@ def update end def create + Book.create(book[:book]) + redirect_to show_path end def destroy diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index dd07ee4bb2..5973e6f5ac 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -34,6 +34,8 @@ def update end def create + movie.create(movie_params[:movie]) + redirect_to show_path end def destroy diff --git a/app/models/album.rb b/app/models/album.rb index 46fa309e4e..b965f608d0 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,2 +1,3 @@ class Album < ActiveRecord::Base + validates :name, presence: true end diff --git a/app/models/book.rb b/app/models/book.rb index 6f68b44465..a121549059 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,2 +1,3 @@ class Book < ActiveRecord::Base + validates :name, presence: true end diff --git a/app/models/movie.rb b/app/models/movie.rb index 49198a7d97..0ed6d496b1 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,2 +1,3 @@ class Movie < ActiveRecord::Base + validates :name, presence: true end diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index b5a188a936..501827dfe0 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -5,7 +5,7 @@ <% @movies.each do |movie| %> Ranked: <%= movie.rank %> - <%= movie.name %> + <%= link_to movie.name, movie_path(movie.id) %> <%= button_to "Upvote", { action: "update" , class: "upvote", id: movie.id}, method: "patch" %> <% end %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index f6e06e0d7c..fcb3b72c86 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -5,5 +5,5 @@ <%= button_to "Upvote", { action: "update" , class: "upvote"}, method: "patch"%> <%= button_to "Edit", { action: "edit", id: @movie.id }, method: :get %> <%= button_to "Delete", action: "destroy", id: @movie.id %> -<%= button_to "View all movies", albums_path, method: :get%> +<%= button_to "View all movies", movies_path, method: :get%> <%= button_to "View all media", root_path, method: :get %> diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb new file mode 100644 index 0000000000..58bb18171c --- /dev/null +++ b/spec/controllers/albums_controller_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe AlbumsController, type: :controller do + describe "GET 'index'" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end +end diff --git a/spec/controllers/books_controller_spec.rb b/spec/controllers/books_controller_spec.rb new file mode 100644 index 0000000000..034e5e082f --- /dev/null +++ b/spec/controllers/books_controller_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe BooksController, type: :controller do + describe "GET 'index'" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end +end diff --git a/spec/controllers/movies_controller_spec.rb b/spec/controllers/movies_controller_spec.rb new file mode 100644 index 0000000000..d3bf540e93 --- /dev/null +++ b/spec/controllers/movies_controller_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe MoviesController, type: :controller do + describe "GET 'index'" do + it "is successful" do + get :index + expect(response.status).to eq 200 + end + end +end diff --git a/spec/helpers/albums_helper_spec.rb b/spec/helpers/albums_helper_spec.rb new file mode 100644 index 0000000000..6897f3acf3 --- /dev/null +++ b/spec/helpers/albums_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the PostsHelper. For example: +# +# describe PostsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe AlbumsHelper, type: :helper do +# pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/books_helper_spec.rb b/spec/helpers/books_helper_spec.rb new file mode 100644 index 0000000000..23e0595f8d --- /dev/null +++ b/spec/helpers/books_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the PostsHelper. For example: +# +# describe PostsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe BooksHelper, type: :helper do +# pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/movies_helper_spec.rb b/spec/helpers/movies_helper_spec.rb new file mode 100644 index 0000000000..420500ceca --- /dev/null +++ b/spec/helpers/movies_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the PostsHelper. For example: +# +# describe PostsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe MoviesHelper, type: :helper do +# pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb new file mode 100644 index 0000000000..6ecb6aa2e8 --- /dev/null +++ b/spec/models/album_spec.rb @@ -0,0 +1,23 @@ +require 'rails_helper' + +RSpec.describe Album, type: :model do + describe ".validates" do + it "must have a name" do + expect(Album.new(name: nil)).to_not be_valid + end + end + + # it "can't have 141 characters" do + # expect(Post.new(bod: "a" * 141)).to be_invalid + # end + # + # it "can have 140 characters" do + # expect(Post.new(bod: "a" * 140)).to be_valid + # end + # end + # + # it "count it's characters" do + # expect(Post.new(bod: "b" * 122).characters_count).to eq 122 + # end + +end diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb new file mode 100644 index 0000000000..24035257c1 --- /dev/null +++ b/spec/models/book_spec.rb @@ -0,0 +1,23 @@ +require 'rails_helper' + +RSpec.describe Book, type: :model do + describe ".validates" do + it "must have a name" do + expect(Book.new(name: nil)).to_not be_valid + end + end + + # it "can't have 141 characters" do + # expect(Post.new(bod: "a" * 141)).to be_invalid + # end + # + # it "can have 140 characters" do + # expect(Post.new(bod: "a" * 140)).to be_valid + # end + # end + # + # it "count it's characters" do + # expect(Post.new(bod: "b" * 122).characters_count).to eq 122 + # end + +end diff --git a/spec/models/movie_spec.rb b/spec/models/movie_spec.rb new file mode 100644 index 0000000000..d23e87ce61 --- /dev/null +++ b/spec/models/movie_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe Movie, type: :model do + describe ".validates" do + it "must have a name" do + expect(Movie.new(name: nil)).to_not be_valid + end + end + + # it "can't have 141 characters" do + # expect(Post.new(bod: "a" * 141)).to be_invalid + # end + # + # it "can have 140 characters" do + # expect(Post.new(bod: "a" * 140)).to be_valid + # end + # end + # + # it "count it's characters" do + # expect(Post.new(bod: "b" * 122).characters_count).to eq 122 + # end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000000..6f1ab14638 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,57 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'spec_helper' +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } + +# Checks for pending migration and applies them before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000000..61e27385c3 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,92 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From c64fc6ac421a5dbac39c62f8185dc4a3cbd06c61 Mon Sep 17 00:00:00 2001 From: Tammy Date: Tue, 1 Dec 2015 13:53:07 -0800 Subject: [PATCH 13/30] fixed some bugs in the indexes --- app/controllers/albums_controller.rb | 2 +- app/controllers/books_controller.rb | 6 +++--- app/controllers/movies_controller.rb | 2 +- app/views/albums/index.html.erb | 4 +++- app/views/books/index.html.erb | 4 +++- app/views/books/show.html.erb | 2 +- app/views/movies/index.html.erb | 2 ++ 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index c20d80ca22..cf5d4cffce 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -36,7 +36,7 @@ def update def create Album.create(album_params[:album]) - redirect_to show_path + redirect_to albums_path end def destroy diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 5cb83a3962..1b39335110 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -9,7 +9,7 @@ def index end def new - @album = Album.new + @book = Book.new end def edit @@ -34,8 +34,8 @@ def update end def create - Book.create(book[:book]) - redirect_to show_path + Book.create(book_params[:book]) + redirect_to books_path end def destroy diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 5973e6f5ac..a1a96c83ff 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -35,7 +35,7 @@ def update def create movie.create(movie_params[:movie]) - redirect_to show_path + redirect_to movies_path end def destroy diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index 5a1c50edb6..36b40b6c1c 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -5,8 +5,10 @@ <% @albums.each do |album| %> Ranked: <%= album.rank %> - <%= album.name %> + <%= link_to album.name, album_path(album.id) %> <%= button_to "Upvote", { action: "update" , class: "upvote", id: album.id}, method: "patch" %> <% end %> +<%= button_to "Add an album", new_album_path, method: :get %> +<%= button_to "View all movies", movies_path, method: :get%> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index fa6103f366..d3638e803f 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -5,8 +5,10 @@ <% @books.each do |book| %> Ranked: <%= book.rank %> - <%= book.name %> + <%= link_to book.name, book_path(book.id) %> <%= button_to "Upvote", { action: "update" , class: "upvote", id: book.id}, method: "patch" %> <% end %> +<%= button_to "Add a book", new_book_path, method: :get %> +<%= button_to "View all movies", movies_path, method: :get%> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 45a75c360c..cdb10943b9 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -5,5 +5,5 @@ <%= button_to "Upvote", { action: "update" , class: "upvote"}, method: "patch"%> <%= button_to "Edit", { action: "edit", id: @book.id }, method: :get %> <%= button_to "Delete", action: "destroy", id: @book.id %> -<%= button_to "View all books", albums_path, method: :get%> +<%= button_to "View all books", books_path, method: :get%> <%= button_to "View all media", root_path, method: :get %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index 501827dfe0..88abcf92de 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -10,3 +10,5 @@ <% end %> +<%= button_to "Add a Movie", new_movie_path, method: :get %> +<%= button_to "View all movies", movies_path, method: :get%> From 93dfe18266e2b8b4c5c952253ca89ef701b6cf11 Mon Sep 17 00:00:00 2001 From: Tammy Date: Tue, 1 Dec 2015 13:58:24 -0800 Subject: [PATCH 14/30] made an if statement so the upvote will work in both different pages --- app/controllers/movies_controller.rb | 7 ++++++- app/views/albums/index.html.erb | 2 +- app/views/books/index.html.erb | 2 +- app/views/movies/index.html.erb | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index a1a96c83ff..29c426445b 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -26,6 +26,11 @@ def update rank = @movie[:rank] + 1 @movie.update(:rank => rank) render "show" + elsif params[:class] == "upvote_i" + get_movie + rank = @movie[:rank] + 1 + @movie.update(:rank => rank) + redirect_to movies_path else get_movie @movie.update(movie_params[:movie]) @@ -34,7 +39,7 @@ def update end def create - movie.create(movie_params[:movie]) + Movie.create(movie_params[:movie]) redirect_to movies_path end diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb index 36b40b6c1c..a36192be6a 100644 --- a/app/views/albums/index.html.erb +++ b/app/views/albums/index.html.erb @@ -11,4 +11,4 @@ <% end %> <%= button_to "Add an album", new_album_path, method: :get %> -<%= button_to "View all movies", movies_path, method: :get%> +<%= button_to "View all media", root_path, method: :get %> diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index d3638e803f..c3149c3902 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -11,4 +11,4 @@ <% end %> <%= button_to "Add a book", new_book_path, method: :get %> -<%= button_to "View all movies", movies_path, method: :get%> +<%= button_to "View all media", root_path, method: :get %> diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb index 88abcf92de..b31e9d1495 100644 --- a/app/views/movies/index.html.erb +++ b/app/views/movies/index.html.erb @@ -6,9 +6,9 @@ Ranked: <%= movie.rank %> <%= link_to movie.name, movie_path(movie.id) %> - <%= button_to "Upvote", { action: "update" , class: "upvote", id: movie.id}, method: "patch" %> + <%= button_to "Upvote", { action: "update" , class: "upvote_i", id: movie.id}, method: "patch" %> <% end %> <%= button_to "Add a Movie", new_movie_path, method: :get %> -<%= button_to "View all movies", movies_path, method: :get%> +<%= button_to "View all media", root_path, method: :get %> From 9beadeb7602dc466fc7f1fc80fe21f19ab4e5ff2 Mon Sep 17 00:00:00 2001 From: Tammy Date: Tue, 1 Dec 2015 14:09:32 -0800 Subject: [PATCH 15/30] all deleting are working --- app/controllers/albums_controller.rb | 2 ++ app/controllers/books_controller.rb | 2 ++ app/controllers/movies_controller.rb | 2 ++ app/views/albums/show.html.erb | 2 +- app/views/books/show.html.erb | 2 +- app/views/movies/show.html.erb | 2 +- 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index cf5d4cffce..fc22cc1396 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -40,6 +40,8 @@ def create end def destroy + Album.destroy(params[:id]) + redirect_to albums_path end private diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 1b39335110..b03335ca77 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -39,6 +39,8 @@ def create end def destroy + Book.destroy(params[:id]) + redirect_to books_path end private diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 29c426445b..68bf41d6c5 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -44,6 +44,8 @@ def create end def destroy + Movie.destroy(params[:id]) + redirect_to movies_path end private diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb index e53b504ce0..d16feb7aa0 100644 --- a/app/views/albums/show.html.erb +++ b/app/views/albums/show.html.erb @@ -4,6 +4,6 @@ <%= button_to "Upvote", { action: "update" , class: "upvote"}, method: "patch"%> <%= button_to "Edit", { action: "edit", id: @album.id }, method: :get %> -<%= button_to "Delete", action: "destroy", id: @album.id %> +<%= button_to "Delete", {action: "destroy", id: @album.id}, method: :delete, data: { confirm: 'Are you sure?' } %> <%= button_to "View all albums", albums_path, method: :get%> <%= button_to "View all media", root_path, method: :get %> diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index cdb10943b9..7f0b404f1d 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -4,6 +4,6 @@ <%= button_to "Upvote", { action: "update" , class: "upvote"}, method: "patch"%> <%= button_to "Edit", { action: "edit", id: @book.id }, method: :get %> -<%= button_to "Delete", action: "destroy", id: @book.id %> +<%= button_to "Delete", { action: "destroy", id: @book.id}, method: :delete, data: { confirm: 'Are you sure?' } %> <%= button_to "View all books", books_path, method: :get%> <%= button_to "View all media", root_path, method: :get %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index fcb3b72c86..43ab9b628e 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -4,6 +4,6 @@ <%= button_to "Upvote", { action: "update" , class: "upvote"}, method: "patch"%> <%= button_to "Edit", { action: "edit", id: @movie.id }, method: :get %> -<%= button_to "Delete", action: "destroy", id: @movie.id %> +<%= button_to "Delete", { action: "destroy", id: @movie.id}, method: :delete, data: { confirm: 'Are you sure?' } %> <%= button_to "View all movies", movies_path, method: :get%> <%= button_to "View all media", root_path, method: :get %> From 993546e49ecfc0edd3bbc0066831e3bcbb9504d7 Mon Sep 17 00:00:00 2001 From: Tammy Date: Tue, 1 Dec 2015 14:31:49 -0800 Subject: [PATCH 16/30] set a default rank=0, and made the validations and display the user in the form --- app/controllers/albums_controller.rb | 8 ++++++-- app/controllers/books_controller.rb | 8 ++++++-- app/controllers/movies_controller.rb | 9 +++++++-- app/models/album.rb | 3 +++ app/models/book.rb | 5 ++++- app/models/movie.rb | 5 ++++- app/views/albums/_form.html.erb | 8 ++++++++ app/views/books/_form.html.erb | 9 +++++++++ app/views/movies/_form.html.erb | 8 ++++++++ 9 files changed, 55 insertions(+), 8 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index fc22cc1396..dae7c50f36 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -35,8 +35,12 @@ def update def create - Album.create(album_params[:album]) - redirect_to albums_path + @album = Album.new(album_params[:album]) + if @album.save + redirect_to albums_path + else + render "new" + end end def destroy diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index b03335ca77..7368322f2d 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -34,8 +34,12 @@ def update end def create - Book.create(book_params[:book]) - redirect_to books_path + @book = Book.new(book_params[:book]) + if @book.save + redirect_to books_path + else + render "new" + end end def destroy diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 68bf41d6c5..aa4e414a77 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -39,8 +39,13 @@ def update end def create - Movie.create(movie_params[:movie]) - redirect_to movies_path + @movie = Movie.new(movie_params[:movie]) + @movie.update(:rank => 0) + if @movie.save + redirect_to movies_path + else + render "new" + end end def destroy diff --git a/app/models/album.rb b/app/models/album.rb index b965f608d0..d39fbcdefe 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,3 +1,6 @@ class Album < ActiveRecord::Base validates :name, presence: true + validates :description, length: {maximum: 200} + validates :description, presence: true + validates :artist, presence: true end diff --git a/app/models/book.rb b/app/models/book.rb index a121549059..0ecb1e3b9f 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -1,3 +1,6 @@ class Book < ActiveRecord::Base - validates :name, presence: true + validates :name, presence: true + validates :description, length: {maximum: 200} + validates :description, presence: true + validates :author, presence: true end diff --git a/app/models/movie.rb b/app/models/movie.rb index 0ed6d496b1..410dd541ac 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -1,3 +1,6 @@ class Movie < ActiveRecord::Base - validates :name, presence: true + validates :name, presence: true + validates :description, length: {maximum: 200} + validates :description, presence: true + validates :director, presence: true end diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb index c0314c885c..7adfaf17c7 100644 --- a/app/views/albums/_form.html.erb +++ b/app/views/albums/_form.html.erb @@ -1,3 +1,11 @@ +
      + <% @movie.errors.each do |column, message| %> +
    • + <%= column.capitalize %> <%= message %> +
    • + <% end %> +
    + <%= form_for @album do |f| %> <%= f.label :Name %>: <%= f.text_field :name, :required => true %> diff --git a/app/views/books/_form.html.erb b/app/views/books/_form.html.erb index 8ecdfd7c20..aaece9963b 100644 --- a/app/views/books/_form.html.erb +++ b/app/views/books/_form.html.erb @@ -1,3 +1,12 @@ +
      + <% @movie.errors.each do |column, message| %> +
    • + <%= column.capitalize %> <%= message %> +
    • + <% end %> +
    + + <%= form_for @book do |f| %> <%= f.label :Name %>: <%= f.text_field :name, :required => true %> diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb index dd2fbd4966..0ffe7fce41 100644 --- a/app/views/movies/_form.html.erb +++ b/app/views/movies/_form.html.erb @@ -1,3 +1,11 @@ +
      + <% @movie.errors.each do |column, message| %> +
    • + <%= column.capitalize %> <%= message %> +
    • + <% end %> +
    + <%= form_for @movie do |f| %> <%= f.label :Name %>: <%= f.text_field :name, :required => true %> From f079caa186818d595e9ee05d9878ce19daf23507 Mon Sep 17 00:00:00 2001 From: Tammy Date: Tue, 1 Dec 2015 14:37:33 -0800 Subject: [PATCH 17/30] fixed some bugs - ready for testing --- app/controllers/albums_controller.rb | 6 ++++++ app/controllers/books_controller.rb | 6 ++++++ app/views/albums/_form.html.erb | 2 +- app/views/albums/index.html.erb | 2 +- app/views/books/_form.html.erb | 2 +- app/views/books/index.html.erb | 2 +- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index dae7c50f36..1b1369bacc 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -26,6 +26,11 @@ def update rank = @album[:rank] + 1 @album.update(:rank => rank) render "show" + elsif params[:class] == "upvote_i" + get_album + rank = @album[:rank] + 1 + @album.update(:rank => rank) + redirect_to albums_path else get_album @album.update(album_params[:album]) @@ -36,6 +41,7 @@ def update def create @album = Album.new(album_params[:album]) + @album.update(:rank => 0) if @album.save redirect_to albums_path else diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 7368322f2d..fa7b31c66b 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -26,6 +26,11 @@ def update rank = @book[:rank] + 1 @book.update(:rank => rank) render "show" + elsif params[:class] == "upvote_i" + get_book + rank = @book[:rank] + 1 + @book.update(:rank => rank) + redirect_to books_path else get_book @book.update(book_params[:book]) @@ -35,6 +40,7 @@ def update def create @book = Book.new(book_params[:book]) + @book.update(:rank => 0) if @book.save redirect_to books_path else diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb index 7adfaf17c7..9983714471 100644 --- a/app/views/albums/_form.html.erb +++ b/app/views/albums/_form.html.erb @@ -1,5 +1,5 @@