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

MediaRanker baseline and some extensions #46

Open
wants to merge 60 commits into
base: jlb/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3af9465
create homepage controller
jbuechs Nov 30, 2015
bba80b3
add better errors and spring to gemfile
jbuechs Nov 30, 2015
ff38fbc
add bootstrap to css and javascript
jbuechs Nov 30, 2015
19d78c4
add default value to upvotes
jbuechs Dec 1, 2015
bd47dc9
create homepage
jbuechs Dec 1, 2015
571defd
create default in migration
jbuechs Dec 1, 2015
155f8ea
create index for all views
jbuechs Dec 1, 2015
3276ebb
create index view for all models
jbuechs Dec 1, 2015
ea579bf
create show page for book
jbuechs Dec 1, 2015
a9eb5a4
create destroy for books
jbuechs Dec 1, 2015
4dff574
create show for all models
jbuechs Dec 1, 2015
b0bf8bf
complete edit and create movie views
jbuechs Dec 1, 2015
8871534
create and edit books
jbuechs Dec 1, 2015
c55f339
add and edit albums
jbuechs Dec 1, 2015
12e8db6
change typos
jbuechs Dec 1, 2015
b3fbdd6
create upvotes for albums
jbuechs Dec 1, 2015
0e30023
upvote for books
jbuechs Dec 1, 2015
384808f
upvote for movies
jbuechs Dec 1, 2015
84a56cd
create random num of upvotes in seed
jbuechs Dec 1, 2015
ae0146b
order results by number of upvotes
jbuechs Dec 1, 2015
9114f8f
refactor form partial
jbuechs Dec 1, 2015
9705ad6
add rspec to project
jbuechs Dec 1, 2015
a907fcc
refactor add and edit to use form partial
jbuechs Dec 1, 2015
8aebab8
create tests for controllers and models
jbuechs Dec 1, 2015
6386c16
refactor index page
jbuechs Dec 1, 2015
94770c8
refactor show pages
jbuechs Dec 1, 2015
66760e6
create empty methods for movies controller
jbuechs Dec 1, 2015
dc3fcf4
add some tests for movies controller
jbuechs Dec 1, 2015
2eaf315
add empty methods to albums and books controller tests
jbuechs Dec 1, 2015
117c398
create test for create fail
jbuechs Dec 1, 2015
d5c4193
change create method to render new page on failed submission
jbuechs Dec 1, 2015
51c871f
create test for patch update
jbuechs Dec 1, 2015
bf2b382
refactor redirecting new movie to show page
jbuechs Dec 1, 2015
6485ffb
create edit test for movie
jbuechs Dec 2, 2015
614348f
create test for upvote
jbuechs Dec 2, 2015
2c58eaa
create delete path
jbuechs Dec 2, 2015
d169cb0
create tests for books controller
jbuechs Dec 2, 2015
352e939
create most tests for albums controller
jbuechs Dec 2, 2015
2298a4f
create tests for albums controller
jbuechs Dec 2, 2015
c415c4d
create test for homepage
jbuechs Dec 2, 2015
cee3119
add pry rails to gemfile
jbuechs Dec 2, 2015
5506d42
style header and other css
jbuechs Dec 2, 2015
8b719dd
create footer
jbuechs Dec 2, 2015
5baefb6
try to refactor album create test
jbuechs Dec 2, 2015
2a8c503
refactor update books controller
jbuechs Dec 2, 2015
3065a0d
change update controllers for failed updates
jbuechs Dec 2, 2015
a7f552b
add error messages to form
jbuechs Dec 2, 2015
b590558
add error output for form and maximum length for title
jbuechs Dec 2, 2015
a99f284
clean out excess comments
jbuechs Dec 2, 2015
26156f0
create shared method concern for controller
jbuechs Dec 2, 2015
7bb2249
dry up tests using shared tests
jbuechs Dec 2, 2015
e6c2b34
remove extra whitespace
jbuechs Dec 2, 2015
e0d522d
add padding to upvote button
jbuechs Dec 2, 2015
6df3c06
change color of links
jbuechs Dec 2, 2015
f44ec28
rename columns to creator
jbuechs Dec 3, 2015
85c1efc
refactor seed file
jbuechs Dec 3, 2015
9885d5c
edit strong params method to match column rename
jbuechs Dec 3, 2015
5aeeaa5
rename field to creator
jbuechs Dec 3, 2015
6a9bb1c
refactor rspec controller tests
jbuechs Dec 3, 2015
4f6ddee
refactor rspec
jbuechs Dec 3, 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
29 changes: 6 additions & 23 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'

Choose a reason for hiding this comment

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

I wouldn't worry about removing these comments. It shouldn't significantly affect performance and it's nice to have these explanations for those that're unfamiliar with these gems.

# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# add bootstrap
gem 'bootstrap-sass', '~> 3.3.6'
gem 'simplecov', :require => false, :group => :test

group :production do
gem 'pg'
end

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'rspec-rails'
gem 'pry-rails'
end

group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'

# gem 'spring'
# Add better errors gems
# gem 'better_errors'
# gem 'binding_of_caller'
# Use sqlite3 as the database for Active Record
gem 'spring'
gem 'better_errors'
gem 'binding_of_caller'
gem 'sqlite3'
# Create ERD for project
gem 'rails-erd'
end
52 changes: 44 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ GEM
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)
coderay (1.1.0)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
Expand All @@ -56,6 +60,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 All @@ -73,13 +79,20 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.99)
mini_portile2 (2.0.0)
minitest (5.8.3)
multi_json (1.11.2)
nokogiri (1.6.7)
mini_portile2 (~> 2.0.0.rc2)
pg (0.18.4)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rails (0.3.4)
pry (>= 0.9.10)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand All @@ -100,11 +113,6 @@ GEM
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-erd (1.4.4)
activerecord (>= 3.2)
activesupport (>= 3.2)
choice (~> 0.2.0)
ruby-graphviz (~> 1.2)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
railties (4.2.5)
Expand All @@ -114,7 +122,23 @@ GEM
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rdoc (4.2.0)
ruby-graphviz (1.2.2)
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)
Expand All @@ -125,6 +149,13 @@ 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)
rack (> 1, < 3)
sprockets-rails (2.3.3)
Expand Down Expand Up @@ -152,16 +183,21 @@ PLATFORMS
ruby

DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
pg
pry-rails
rails (= 4.2.5)
rails-erd
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simplecov
spring
sqlite3
turbolinks
uglifier (>= 1.3.0)
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.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@
* 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: image-url(owl.jpg);
background-repeat: no-repeat;
padding-bottom: 9px;
margin: 40px 0 20px;
border-bottom: 1px solid #eee;
}

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

thead td {
font-weight: bold;
}

form .btn-primary {
margin-bottom: 10px;
}

a {
color: #428bca;
}
43 changes: 43 additions & 0 deletions app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
class AlbumsController < ApplicationController
include SharedMethods
before_action :get_album, only:[:show, :destroy, :update, :edit, :upvote]
def index
@albums = Album.all.order(:upvotes).reverse
end

def new
@album = Album.new
end

def destroy
@album.destroy
redirect_to albums_path
end

def update
@album.update(album_params[:album]) ? (redirect_to album_path(@album)) : (render :edit)
end

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

def upvote
@album.upvotes += 1

Choose a reason for hiding this comment

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

You can write @album.upvotes.increment! which will auto-increment the value by 1 and save it. See the documentation.

@album.save
redirect_to album_path(@album)
end

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

def album_params
params.permit(album:[:id, :title, :creator, :description, :upvotes])
end
end
43 changes: 43 additions & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
class BooksController < ApplicationController
include SharedMethods
before_action :get_book, only:[:show, :destroy, :update, :edit, :upvote]
def index
@books = Book.all.order(:upvotes).reverse
end

def new
@book = Book.new
end

def destroy
@book.destroy
redirect_to books_path
end

def update
@book.update(book_params[:book]) ? (redirect_to book_path(@book)) : (render :edit)
end

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

def upvote
@book.upvotes += 1
@book.save
redirect_to book_path(@book)
end

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

def book_params
params.permit(book:[:id, :title, :creator, :description, :upvotes])
end
end
13 changes: 13 additions & 0 deletions app/controllers/concerns/shared_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module SharedMethods

Choose a reason for hiding this comment

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

So close!! I'm assuming you wanted to use Rails's new ActiveModel concerns? First, awesome job recognizing the opportunity to DRY up your code! 👍🏾I found a post about using concerns by DHH himself, but I found it a bit hard to understand. This walkthrough, with a before and after of a model, was easier to digest.

extend ActiveSupport::Concern

module ClassMethods
def edit
end

def show
end

end

end
6 changes: 6 additions & 0 deletions app/controllers/homepage_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
class HomepageController < ApplicationController
def index
max = 10
@books = Book.limit(max).order(:upvotes).reverse
@movies = Movie.limit(max).order(:upvotes).reverse
@albums = Album.limit(max).order(:upvotes).reverse
end
end
44 changes: 44 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
class MoviesController < ApplicationController
include SharedMethods
before_action :get_movie, only:[:show, :destroy, :update, :edit, :upvote]

def index
@movies = Movie.all.order(:upvotes).reverse
end

def new
@movie = Movie.new
end

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

def destroy
@movie.destroy
redirect_to movies_path
end

def update
@movie.update(movie_params[:movie]) ? (redirect_to movie_path(@movie)) : (render :edit)
end

def upvote
@movie.upvotes += 1
@movie.save
redirect_to movie_path(@movie)
end

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

def movie_params
params.permit(movie:[:id, :title, :creator, :description, :upvotes])
end
end
4 changes: 2 additions & 2 deletions app/models/album.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Album < ActiveRecord::Base
validates :title, presence: true
validates :artist, presence: true
validates :title, presence: true, length: { maximum: 25 }
validates :creator, presence: true
end
Loading