-
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
Complete MediaRanker #42
base: dfp/master
Are you sure you want to change the base?
Changes from all commits
7a7b397
4b81b42
dab484b
88d391c
7a749a7
ef1da81
9da5b38
e7d95e2
8178be3
096e7be
4cbabaa
ec13745
3e5dd1d
34d2f0f
dac12cd
32131e2
1008df3
923e5fc
30979ef
28ceb15
ab2a52e
26026f1
928cecf
d48562c
e881c8b
026fccf
b0d94df
c62d1dd
68d356f
1e2c1b0
fa3325f
2cbb090
1d70ef0
91dda9a
e40a195
1d718d1
947e4d1
5efb398
71c4ee6
3bee303
a845fc1
073c88e
989f9ce
ac616ba
f202f95
bf9991a
591c69a
99f77d2
8c3fd91
e3f0af1
a87ff82
d7d0c0a
4aebbf0
6808992
66e2fbb
c95a96c
1c95ec3
9d091b5
a0e02f7
f245288
b509d13
9454378
cac2b1e
dd1a0da
aac1445
09a337f
13c0988
5aa5f3d
038042c
e683bed
c6c9cbe
96e0553
be73f8f
51ceb13
18610f5
1a2700f
c2276ae
8e6b899
14e8db1
6641959
09675a0
78a7408
752f46f
9c2a358
26b62fb
ace940c
7dd3f96
a521fdb
31243ec
5158568
32688a5
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--require spec_helper |
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/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ | |
//= require jquery_ujs | ||
//= require turbolinks | ||
//= require_tree . | ||
//= require bootstrap-sprockets |
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/ |
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/ |
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/ |
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 |
---|---|---|
@@ -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/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the media 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 |
---|---|---|
@@ -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/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class AlbumsController < ApplicationController | ||
|
||
def index | ||
@albums = Album.all.order(:upvotes).reverse | ||
end | ||
|
||
def show | ||
@album = Album.find(params[:id]) | ||
end | ||
|
||
def new | ||
@album = Album.new | ||
end | ||
|
||
def edit | ||
@album = Album.find(params[:id]) | ||
end | ||
|
||
def create | ||
@album = Album.new(album_params) | ||
if @album.save | ||
redirect_to album_path(@album.id) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
@album = Album.update(params[:id], album_params) | ||
if @album.save | ||
redirect_to album_path(@album.id) | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
Album.find(params[:id]).destroy | ||
redirect_to albums_path | ||
end | ||
|
||
def upvote | ||
album = Album.find(params[:id]) | ||
album.upvotes += 1 | ||
album.save! | ||
redirect_to album_path(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def album_params | ||
params.require(:album).permit(:name, :artist, :description) | ||
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. Nice use of strong params! #security |
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class BooksController < ApplicationController | ||
|
||
def index | ||
@books = Book.all.order(:upvotes).reverse | ||
end | ||
|
||
def show | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def new | ||
@book = Book.new | ||
end | ||
|
||
def edit | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def create | ||
@book = Book.new(book_params) | ||
if @book.save | ||
redirect_to book_path(@book.id) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
@book = Book.update(params[:id], book_params) | ||
if @book.save | ||
redirect_to book_path(@book.id) | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
Book.find(params[:id]).destroy | ||
redirect_to books_path | ||
end | ||
|
||
def upvote | ||
book = Book.find(params[:id]) | ||
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. The same |
||
book.upvotes += 1 | ||
book.save! | ||
redirect_to book_path(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def book_params | ||
params.require(:book).permit(:name, :author, :description) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class MediaController < ApplicationController | ||
def index | ||
@books = Book.all.order(:upvotes).reverse.take(10) | ||
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. This could be a good place to use a model scope. Example in controller: Example in the Book model: |
||
@albums = Album.all.order(:upvotes).reverse.take(10) | ||
@movies = Movie.all.order(:upvotes).reverse.take(10) | ||
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 could consider using a constant here to hold the number of media you want to display. That way if it changes later on, you only need to update it in one place instead of three. |
||
end | ||
end | ||
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. Nice clean controller! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class MoviesController < ApplicationController | ||
|
||
def index | ||
@movies = Movie.all.order(:upvotes).reverse | ||
end | ||
|
||
def show | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def new | ||
@movie = Movie.new | ||
end | ||
|
||
def edit | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def create | ||
@movie = Movie.new(movie_params) | ||
if @movie.save | ||
redirect_to movie_path(@movie.id) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
@movie = Movie.update(params[:id], movie_params) | ||
if @movie.save | ||
redirect_to movie_path(@movie.id) | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
Movie.find(params[:id]).destroy | ||
redirect_to movies_path | ||
end | ||
|
||
def upvote | ||
movie = Movie.find(params[:id]) | ||
movie.upvotes += 1 | ||
movie.save! | ||
redirect_to movie_path(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def movie_params | ||
params.require(:movie).permit(:name, :director, :description) | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AlbumsHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module BooksHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module MediaHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module MoviesHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Album < ActiveRecord::Base | ||
validates :name, presence: true, uniqueness: true | ||
end | ||
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. This would be where you could add in those scopes mentioned in earlier comment. Example: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Book < ActiveRecord::Base | ||
validates :name, presence: true, uniqueness: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Movie < ActiveRecord::Base | ||
validates :name, presence: true, uniqueness: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h2>Edit Album</h2> | ||
<%= render partial: "shared/form", locals: { | ||
media: @album, | ||
creator: :artist | ||
} %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<%= render partial: "shared/index", locals: { | ||
medias: @albums, | ||
media: "album", | ||
upvote: "upvote_album_path", | ||
new_media: "new_album_path", | ||
one_media: "An Album" | ||
} %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h2>New Album</h2> | ||
<%= render partial: "shared/form", locals: { | ||
media: @album, | ||
creator: :artist | ||
} %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%= render partial: "shared/show", locals: { | ||
media: @album, | ||
type: "Albums", | ||
creator: @album.artist, | ||
creator_action: "Recorded", | ||
upvote: "upvote_album_path", | ||
edit_media: "edit_album_path", | ||
media_path: "album_path", | ||
medias_path: "albums_path" | ||
} %> |
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.
It looks like you search for this album in multiple methods. A possible way you could DRY up your code in a refactor would be to extract finding the album into its own private method and create a
before_action
that calls it before each methodexcept: [:index, :new, :create]
.