Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final submission for final wave of Media Ranker #40

Open
wants to merge 33 commits into
base: sat/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f3b274d
Created Movie, Book and Album models
trowbrsa Nov 30, 2015
7036302
generated books, movies and albums controllers
trowbrsa Nov 30, 2015
68d1dd1
generated routes for 3 models
trowbrsa Nov 30, 2015
c74fa0c
Added all standard methods and views for movies controller
trowbrsa Nov 30, 2015
ee9a783
Added views and methods for books class
trowbrsa Nov 30, 2015
510c87b
unworking method for upvotes
trowbrsa Dec 1, 2015
05a1022
Working upvote method
trowbrsa Dec 1, 2015
12b538d
Made a named route for upvote movie path, added link to movie index page
trowbrsa Dec 1, 2015
5b1d254
Added specs for create, new, index methods
trowbrsa Dec 1, 2015
bea4a5f
Successfully created update spec for movies
trowbrsa Dec 1, 2015
9b42653
Added Bootstrap
trowbrsa Dec 2, 2015
fc22e9b
Added simplecov gem
trowbrsa Dec 2, 2015
81d52d2
Successfully created spec for update method
trowbrsa Dec 2, 2015
4643c2d
Working method for upvote
trowbrsa Dec 2, 2015
c404605
Created test for testing incrementation and redirect of upvote method
trowbrsa Dec 2, 2015
0a29eb8
Added additional bootstrap styling
trowbrsa Dec 3, 2015
31616e0
Added errors message when title not included
trowbrsa Dec 3, 2015
ec1656a
Added new medium controller spec
trowbrsa Dec 3, 2015
3bd514b
Added album views and controller methods
trowbrsa Dec 3, 2015
9ea93de
Updated home view
trowbrsa Dec 3, 2015
4c948e3
Updated show view for books
trowbrsa Dec 3, 2015
8aeb300
Added method to show top 10 ranked items on home page
trowbrsa Dec 4, 2015
92e7114
Added method for upvoting on show page of albums
trowbrsa Dec 4, 2015
bc45bef
Added additional bootstrap styling to show view
trowbrsa Dec 4, 2015
233d91b
Added additional bootstrap styling
trowbrsa Dec 4, 2015
06eb3ca
Generalized movie rspec tests to make availabel for all controllers
trowbrsa Dec 4, 2015
c29c608
Refined rspec tests to make them work
trowbrsa Dec 4, 2015
f4c2d6b
Wrote more tests for album and books controller
trowbrsa Dec 4, 2015
bee34d9
Updated bootstrap on home page
trowbrsa Dec 4, 2015
0e3d975
Updated specs
trowbrsa Dec 4, 2015
3885c21
Generalized all tests for each controller
trowbrsa Dec 4, 2015
38203b4
Added bootstrap styling to 'show' view for all controllers
trowbrsa Dec 6, 2015
9a2756d
Finalized 'edit' method for books and albums controller
trowbrsa Dec 6, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
/log/*
!/log/.keep
/tmp

coverage
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
Expand Down Expand Up @@ -35,6 +36,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'rspec-rails'
gem 'simplecov', :require => false
end

group :development do
Expand Down
33 changes: 33 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
autoprefixer-rails (6.1.2)
execjs
json
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)
bootstrap-sass (3.3.6)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2)
byebug (8.2.1)
choice (0.2.0)
Expand All @@ -55,6 +61,8 @@ GEM
execjs
coffee-script-source (1.10.0)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
docile (1.1.5)
erubis (2.7.0)
execjs (2.6.0)
globalid (0.3.6)
Expand Down Expand Up @@ -112,6 +120,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)
ruby-graphviz (1.2.2)
sass (3.4.19)
sass-rails (5.0.4)
Expand All @@ -123,6 +148,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
simplecov (0.11.1)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
spring (1.5.0)
sprockets (3.4.1)
rack (> 1, < 3)
Expand Down Expand Up @@ -153,14 +183,17 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
rails (= 4.2.5)
rails-erd
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simplecov
spring
sqlite3
turbolinks
Expand Down
Binary file added app/assets/images/owl.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/owl.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/owl_final.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/albums.coffee
Original file line number Diff line number Diff line change
@@ -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/
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// about supported directives.
//
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require_tree .
3 changes: 3 additions & 0 deletions app/assets/javascripts/books.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/movies.coffee
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/albums.scss
Original file line number Diff line number Diff line change
@@ -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/
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
Expand All @@ -10,6 +11,18 @@
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
@import "bootstrap-sprockets";
@import "bootstrap";

.page-header {
background: url("owl_final.jpg");
background-repeat: no-repeat;
padding-bottom: 9px;
margin: 40px 0 20px;
border-bottom: 1px solid #eee;
}

.page-header h1 {
margin-left: 150px;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/books.scss
Original file line number Diff line number Diff line change
@@ -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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/movies.scss
Original file line number Diff line number Diff line change
@@ -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/
68 changes: 68 additions & 0 deletions app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class AlbumsController < ApplicationController

def index
@albums = Album.all
end

def new
@title = "Add an Album"
@action = :create
@album = Album.new
end

def create
@album = Album.new(album_params[:album])
if @album.save
redirect_to album_path(@album)
else
render "new"
end
end

def show
id = params[:id]
@album = Album.find(id)
end

def edit
@title = "Edit an Album"
id = params[:id]
@album = Album.find(id)
@action = :update
end

def update
@value = params[:ranking]
id = params[:id]
@album = Album.find(id)
@album.attributes = album_params[:album]
if @album.save
redirect_to album_path(params[:id])
else
@title = "Edit an album"
@action = :update
render :edit
end
end

def destroy
Album.destroy(params[:id])
redirect_to albums_path
end

def upvote
id = params[:id]
album = Album.find(id)
r = album.ranking
r += 1
album.update(ranking: r)
redirect_to :back
end

private

def album_params
params.permit(album:[:author, :title, :ranking, :description])
end

end
70 changes: 70 additions & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class BooksController < ApplicationController
def index
@books = Book.all
end

def new
@title = "Add a Book"
@action = :create
@book = Book.new
end


def create
@title = "Add a book"
@book = Book.new(book_params[:book])
@book.update(:ranking => 0)
if @book.save
redirect_to book_path(@book)
else
render "new"
end
end

def show
id = params[:id]
@book = Book.find(id)
end

def edit
@title = "Edit a book"
id = params[:id]
@book = Book.find(id)
@action = :update
end

def update
@value = params[:ranking]
id = params[:id]
@book = Book.find(id)
@book.attributes = book_params[:book]
if @book.save
redirect_to book_path(params[:id])
else
@title = "Edit a book"
@action = :update
render :edit
end
end


def destroy
Book.destroy(params[:id])
redirect_to books_path
end

def upvote
id = params[:id]
book = Book.find(id)
r = book.ranking
r += 1
book.update(ranking: r)
redirect_to :back
end

private

def book_params
params.permit(book:[:author, :title, :ranking, :description])
end
end
76 changes: 76 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
class MoviesController < ApplicationController

def home
@movies = Movie.all.order(:ranking).reverse.take(10)
@books = Book.all.order(:ranking).reverse.take(10)
@albums = Album.all.order(:ranking).reverse.take(10)
end

def index
@movies = Movie.all
end

def new
@action = :create
@movie = Movie.new
end

def create
@title = "Add a movie"
@movie = Movie.new(movie_params[:movie])
@movie.update(:ranking => 0)
if @movie.save
redirect_to movie_path(@movie)
else
render :new
end
end

def show
id = params[:id]
@movie = Movie.find(id)
end

def edit
@title = "Edit a movie"
id = params[:id]
@movie = Movie.find(id)
@action = :update
end

## use attributes, save it to a local variable (its a hash)
# then use .save boolean to test against
def update
@value = params[:ranking]
id = params[:id]
@movie = Movie.find(id)
@movie.attributes = movie_params[:movie]
if @movie.save
redirect_to movie_path(params[:id])
else
@title = "Edit a movie"
@action = :update
render :edit
end
end

def destroy
Movie.destroy(params[:id])
redirect_to movies_path
end

def upvote
id = params[:id]
movie = Movie.find(id)
r = movie.ranking
r += 1
movie.update(ranking: r)
redirect_to :back
end

private

def movie_params
params.permit(movie: [:title, :director, :ranking, :description])
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your initial setup of individual controllers for book, movie and albums are very clean. Nice.

2 changes: 2 additions & 0 deletions app/helpers/albums_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AlbumsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/books_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BooksHelper
end
2 changes: 2 additions & 0 deletions app/helpers/movies_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MoviesHelper
end
5 changes: 5 additions & 0 deletions app/models/album.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Album < ActiveRecord::Base

validates :title, presence: true

end
Loading