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

Submitting MediaRanker #31

Open
wants to merge 38 commits into
base: erg/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
36502ae
Created models and controllers for movies, books and albums
emgord Nov 30, 2015
8a74a2b
oops forgot to save, igrated db again
emgord Nov 30, 2015
5dcc343
added resources routes for movies, books and albums
emgord Nov 30, 2015
5ef1452
added index page for movies
emgord Nov 30, 2015
a98198e
added new and create method for movie
emgord Nov 30, 2015
7ace56f
created show page for movie
emgord Nov 30, 2015
196dc63
added edit and update for movies
emgord Nov 30, 2015
64740ef
added Delete method for movies
emgord Nov 30, 2015
e6c3c7e
added upvote function to movie detail page
emgord Nov 30, 2015
538cbf5
added upvote to main movie page and sorted by rank
emgord Nov 30, 2015
e238363
created partial for index page
emgord Dec 1, 2015
49ff71d
added index for books
emgord Dec 1, 2015
172608c
added index for albums, seed data, and upvote for albums and books
emgord Dec 1, 2015
98db05d
added rspec
emgord Dec 1, 2015
e9c0d4e
added validation for name on movies
emgord Dec 1, 2015
2271b5f
added simplecov
emgord Dec 1, 2015
05ecd42
adding specs for movie controller
emgord Dec 2, 2015
6ee89b1
added spec for upvote
emgord Dec 2, 2015
6c4a425
added bootstrap styling
emgord Dec 2, 2015
aee69fa
added home controller and page
emgord Dec 2, 2015
c87dae5
added home page, still need to rank media and only show top 10
emgord Dec 3, 2015
bdaefc4
ranked and grabbed top ten for home page, added general medium spec a…
emgord Dec 3, 2015
48a9306
successfully created shared spec for movie
emgord Dec 3, 2015
6bc50d1
added spec to validate presence of name for album and book, and valid…
emgord Dec 3, 2015
1206892
movied all movie specs to shared specs
emgord Dec 3, 2015
0b5d70a
added tests for books and albums
emgord Dec 3, 2015
a23f32a
added test for home controller
emgord Dec 3, 2015
53d5b93
updated form partial so it can be used for all media.
emgord Dec 3, 2015
f266666
added new and create for album and book
emgord Dec 3, 2015
411d76c
created partial for the show and got it working for movie
emgord Dec 3, 2015
18bc3a1
added show for albums and books
emgord Dec 3, 2015
b768ce9
added edit method for album and books
emgord Dec 3, 2015
333f716
added delete for albums and movies
emgord Dec 3, 2015
dea3373
fixed typos and got all specs working
emgord Dec 3, 2015
e39af02
double checked that styling is all the same, made a few small changes
emgord Dec 3, 2015
346df5c
added test to make sure update is actually changing as expected, and …
emgord Dec 4, 2015
24db221
project complete
emgord Dec 4, 2015
6d95929
just kidding. added validation for max length of name, description an…
emgord Dec 4, 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
7 changes: 6 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record

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 @@ -33,6 +33,11 @@ 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'
end

group :test do
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 @@ -120,6 +128,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 @@ -131,6 +156,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
simplecov (0.11.0)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
spring (1.5.0)
sprockets (3.4.1)
Expand Down Expand Up @@ -162,6 +192,7 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
Expand All @@ -170,8 +201,10 @@ DEPENDENCIES
pry-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.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/album.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/home.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/album.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the album 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
Expand Up @@ -10,6 +10,20 @@
* 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-image: image-url("owl.jpg");
background-repeat: no-repeat;
}

.page-header h1 {
margin-left: 150px;
}

form .btn-primary {
margin-bottom: 10px;
}
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/home.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the home 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/
56 changes: 56 additions & 0 deletions app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class AlbumsController < ApplicationController

def index
@albums = Album.all.sort_by { |album| -album.rank }
end

def upvote
album = Album.find(params[:id])
album.rank += 1
album.save
Copy link

Choose a reason for hiding this comment

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

👍 There's also a cool .increment! method that does the same thing as lines 9-10.

redirect_to album_path(album)
end

def new
@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
@album = Album.find(params[:id])
end

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

def update
@album = Album.find(params[:id])
@album.update( album_params[:album])
if @album.save
redirect_to album_path(@album)
else
render "edit"
end
end

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

private

def album_params
params.permit(album:[:name, :artist, :description, :rank])
end

end
57 changes: 57 additions & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class BooksController < ApplicationController

def index
@books = Book.all.sort_by { |book| -book.rank }
end

def upvote
book = Book.find(params[:id])
book.rank += 1
book.save
redirect_to book_path(book)
end

def new
@book = Book.new
end

def create
@book = Book.new(book_params)
if @book.save
redirect_to book_path(@book)
else
render "new"
end
end

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

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

def update
@book = Book.find(params[:id])
@book.update( book_params )
if @book.save
redirect_to book_path(@book)
else
render "edit"
end
end

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

private

def book_params
params.require(:book).permit(:name, :author, :description, :rank)
end


end
8 changes: 8 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class HomeController < ApplicationController

def index
@movies = Movie.all.sort_by { |movie| -movie.rank }.first(10)
@albums = Album.all.sort_by { |album| -album.rank }.first(10)
@books = Book.all.sort_by { |book| -book.rank }.first(10)
Copy link

Choose a reason for hiding this comment

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

If this application had to be maintained (and expanded to other media types) in the future, this would be a great case for using a constant to store the 10.

end
end
57 changes: 57 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class MoviesController < ApplicationController

def index
@movies = Movie.all.sort_by { |movie| -movie.rank }
end

def new
@movie = Movie.new
end

def create
@movie = Movie.new(movie_params[:movie])
if @movie.save
redirect_to movie_path(@movie)
else
render "new"
end
end

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

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

def update
@movie = Movie.find(params[:id])
@movie.update( movie_params[:movie])
if @movie.save
redirect_to movie_path(@movie)
else
render "edit"
end
end

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

def upvote
movie = Movie.find(params[:id])
movie.rank += 1
movie.save
redirect_to movie_path(movie)
end

private

def movie_params
params.permit(movie:[:name, :director, :description, :rank])
end


end
2 changes: 2 additions & 0 deletions app/helpers/album_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AlbumHelper
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/home_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module HomeHelper
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
6 changes: 6 additions & 0 deletions app/models/album.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Album < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 100 }
validates :description, length: {maximum: 500 }
validates :artist, length: {maximum: 100 }

end
6 changes: 6 additions & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Book < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 100 }
validates :description, length: {maximum: 500 }
validates :author, length: {maximum: 100 }

end
6 changes: 6 additions & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Movie < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 100 }
validates :description, length: {maximum: 500 }
validates :director, length: {maximum: 100 }

end
2 changes: 2 additions & 0 deletions app/views/albums/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= render partial:'shared/form',
locals:{ medium: @album, action: :update, title: "Edit Album", creator: :artist, rank_value: @album.rank} %>
2 changes: 2 additions & 0 deletions app/views/albums/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= render partial:'shared/index',
locals:{media:@albums, media_type: :album } %>
2 changes: 2 additions & 0 deletions app/views/albums/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= render partial:'shared/form',
locals:{ medium: @album, action: :create, title: "New Album", creator: :artist, rank_value: 0} %>
Loading