-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: jlb/master
Are you sure you want to change the base?
Changes from all commits
3af9465
bba80b3
ff38fbc
19d78c4
bd47dc9
571defd
155f8ea
3276ebb
ea579bf
a9eb5a4
4dff574
b0bf8bf
8871534
c55f339
12e8db6
b3fbdd6
0e30023
384808f
84a56cd
ae0146b
9114f8f
9705ad6
a907fcc
8aebab8
6386c16
94770c8
66760e6
dc3fcf4
2eaf315
117c398
d5c4193
51c871f
bf2b382
6485ffb
614348f
2c58eaa
d169cb0
352e939
2298a4f
c415c4d
cee3119
5506d42
8b719dd
5baefb6
2a8c503
3065a0d
a7f552b
b590558
a99f284
26156f0
7bb2249
e6c2b34
e0d522d
6df3c06
f44ec28
85c1efc
9885d5c
5aeeaa5
6a9bb1c
4f6ddee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ | |
/log/* | ||
!/log/.keep | ||
/tmp | ||
|
||
coverage |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--require spec_helper |
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' | ||
# 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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can write |
||
@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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module SharedMethods | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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 |
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 |
There was a problem hiding this comment.
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.