-
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
Completed Media Ranker #29
base: KED/master
Are you sure you want to change the base?
Changes from 62 commits
cda108c
4792c90
c3d93d2
7febcc9
de26c24
994b7cb
d4b318c
ecb205a
a790342
d5c74fd
3c9847e
a3aecd6
14c38f3
1f3a49c
c94ac27
6930d6b
01450e5
02822b6
e360b69
8fb8a13
c89bcee
b6d2764
bc49cc2
ad730c9
80ac720
3cda762
836d0af
2a1b470
78245b3
a753812
f79af1e
77f0c52
cab896f
1c0060f
392006d
cfdf599
d23dd2b
c46ed1a
4ea084b
e79c849
131373e
c8c91a4
fcad9cb
464b1d4
ab3ec47
e1c51e8
6dee57c
e833054
0b63f4f
79af199
25743dd
145af64
8a0ba69
d102896
fac53c8
eacd01e
7c69b5b
ae16f87
fec3d5a
b88cc42
c7cf364
781903a
85340db
54cb442
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,4 @@ | |
/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 |
---|---|---|
@@ -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 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 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,3 @@ | ||
// Place all the styles related to the welcome 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,56 @@ | ||
class AlbumsController < ApplicationController | ||
before_action :get_album, only: [:show, :edit, :destroy, :upvote, :update] | ||
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. Excellent time to use a |
||
|
||
def get_album | ||
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. Traditionally all methods used as |
||
@album = Album.find(params[:id]) | ||
end | ||
|
||
def index | ||
@albums = Album.order(ranked: :desc) | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
@album = Album.new | ||
end | ||
|
||
def create | ||
@album = Album.create(album_params) | ||
if @album.save | ||
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. Because |
||
redirect_to album_path(@album) | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
@album.update(album_params) | ||
if @album.save | ||
redirect_to album_path(@album) | ||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
@album.destroy | ||
redirect_to albums_path | ||
end | ||
|
||
def upvote | ||
@album.ranked += 1 | ||
@album.save | ||
redirect_to album_path(@album) | ||
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. I like that you did not include Because none of our routes intend for the user to directly modify the |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class BooksController < ApplicationController | ||
before_action :get_book, only: [:show, :edit, :destroy, :upvote, :update] | ||
|
||
def get_book | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def index | ||
@books = Book.order(ranked: :desc) | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
@book = Book.new | ||
end | ||
|
||
def create | ||
@book = Book.create(book_params) | ||
if @book.save | ||
redirect_to book_path(@book) | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
@book.update(book_params) | ||
if @book.save | ||
redirect_to book_path(@book) | ||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
@book.destroy | ||
redirect_to books_path | ||
end | ||
|
||
def upvote | ||
@book.ranked += 1 | ||
@book.save | ||
redirect_to book_path(@book) | ||
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,56 @@ | ||
class MoviesController < ApplicationController | ||
before_action :get_movie, only: [:show, :edit, :destroy, :upvote, :update] | ||
|
||
def get_movie | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def index | ||
@movies = Movie.order(ranked: :desc) | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
@movie = Movie.new | ||
end | ||
|
||
def create | ||
@movie = Movie.create(movie_params) | ||
if @movie.save | ||
redirect_to movie_path(@movie) | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
@movie.update(movie_params) | ||
if @movie.save | ||
redirect_to movie_path(@movie) | ||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
@movie.destroy | ||
redirect_to movies_path | ||
end | ||
|
||
def upvote | ||
@movie.ranked += 1 | ||
@movie.save | ||
redirect_to movie_path(@movie) | ||
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,7 @@ | ||
class WelcomeController < ApplicationController | ||
def index | ||
@movies = Movie.order(ranked: :desc).limit(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. Because we use def Movie < ActiveRecord::Base
# ...
def self.by_rank
return self.order(ranked: :desc)
end
# OR...
scope :by_rank, -> { order(ranked: :desc) }
end And then you can use it as: |
||
@books = Book.order(ranked: :desc).limit(10) | ||
@albums = Album.order(ranked: :desc).limit(10) | ||
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 MoviesHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module WelcomeHelper | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Album < ActiveRecord::Base | ||
validates :name, presence: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Book < ActiveRecord::Base | ||
validates :name, presence: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Movie < ActiveRecord::Base | ||
validates :name, presence: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h2>Edit Album</h2> | ||
<%= render partial: 'shared/form', locals: { medium: @album, creator_field: :artist } %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render partial: 'shared/index', locals: { media: @albums, name: "album" } %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h2>New Album</h2> | ||
<%= render partial: 'shared/form', locals: { medium: @album, creator_field: :artist } %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render partial: 'shared/show', locals: { medium: @album, name: "album", creator: @album.artist, create_type: "Recorded" } %> | ||
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 very, very DRY... like a strong Chardonnay, or this joke. Also, I don't think the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h2>Edit Book</h2> | ||
<%= render partial: 'shared/form', locals: { medium: @book, creator_field: :author } %> |
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's not much of an issue to have this included in the project repo, although you could have put this
.rspec
file in your home directory and it would work for your local machine (across all projects).