-
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
Ricky final media ranker #27
base: ricky/master
Are you sure you want to change the base?
Changes from 40 commits
0ad887e
f04d922
fb74d4b
17ac202
0922379
e6f10ce
cd61aa7
348c2c5
ef951c5
038ee47
1b2d1b9
e633fc5
2bc22e3
45eefa1
0370957
4833112
901ea3c
40eb52f
d9d5862
3caf884
da3d4f6
c20958d
92f012e
1402b96
dfeac1b
d825093
7045e6a
2db2508
2164ee8
b5a556d
38f0509
34f454f
e9b58c5
cddfea7
1895ed7
dacc948
c8be616
d9b7f3f
d1f61a7
65a9d98
56b2e4d
5f4e277
ee0b124
ca2fa70
f594ef8
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,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,56 @@ | ||
class AlbumsController < ApplicationController | ||
def index | ||
@media = Album.order(ranking: :desc) | ||
end | ||
|
||
def show | ||
@media = Album.find(params[:id]) | ||
end | ||
|
||
def new | ||
@media = Album.new | ||
end | ||
|
||
def create | ||
@media = Album.new(strong_params) | ||
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. We could also do: @media = Album.create(strong_params) do |album|
album.ranking = 0
end
if @media.persisted?
# ...
end |
||
@media.ranking = 0 | ||
if @media.save | ||
redirect_to album_path(@media.id) | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def edit | ||
@media = Album.find(params[:id]) | ||
end | ||
|
||
def update | ||
@media = Album.find(params[:id]) | ||
@media.attributes = strong_params | ||
if @media.save | ||
render "show" | ||
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. What are the trade-offs between using |
||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
album = Album.find(params[:id]) | ||
album.destroy | ||
redirect_to albums_path | ||
end | ||
|
||
def upvote | ||
@media = Album.find(params[:id]) | ||
@media.ranking += 1 | ||
@media.save | ||
render "show" | ||
end | ||
|
||
private | ||
|
||
def strong_params | ||
params.require(:album).permit(:name, :artist, :description, :ranking) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class BooksController < ApplicationController | ||
def index | ||
@media = Book.order(ranking: :desc) | ||
end | ||
|
||
def show | ||
@media = Book.find(params[:id]) | ||
end | ||
|
||
def new | ||
@media = Book.new | ||
end | ||
|
||
def create | ||
@media = Book.new(strong_params) | ||
@media.ranking = 0 | ||
if @media.save | ||
redirect_to book_path(@media.id) | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def edit | ||
@media = Book.find(params[:id]) | ||
end | ||
|
||
def update | ||
@media = Book.find(params[:id]) | ||
@media.attributes = strong_params | ||
if @media.save | ||
render "show" | ||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
book = Book.find(params[:id]) | ||
book.destroy | ||
redirect_to books_path | ||
end | ||
|
||
def upvote | ||
@media = Book.find(params[:id]) | ||
@media.ranking += 1 | ||
@media.save | ||
render "show" | ||
end | ||
|
||
private | ||
|
||
def strong_params | ||
params.require(:book).permit(:name, :author, :description, :ranking) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class MoviesController < ApplicationController | ||
def index | ||
@media = Movie.order(ranking: :desc) | ||
end | ||
|
||
def show | ||
@media = Movie.find(params[:id]) | ||
end | ||
|
||
def new | ||
@media = Movie.new | ||
end | ||
|
||
def create | ||
@media = Movie.new(strong_params) | ||
@media.ranking = 0 | ||
if @media.save | ||
redirect_to movie_path(@media.id) | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def edit | ||
@media = Movie.find(params[:id]) | ||
end | ||
|
||
def update | ||
@media = Movie.find(params[:id]) | ||
@media.attributes = strong_params | ||
if @media.save | ||
render "show" | ||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
movie = Movie.find(params[:id]) | ||
movie.destroy | ||
redirect_to movies_path | ||
end | ||
|
||
def upvote | ||
@media = Movie.find(params[:id]) | ||
@media.ranking += 1 | ||
@media.save | ||
render "show" | ||
end | ||
|
||
private | ||
|
||
def strong_params | ||
params.require(:movie).permit(:name, :director, :description, :ranking) | ||
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,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 @@ | ||
<%= render 'form' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render partial: "index", locals: { class_type: Album } %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render 'form' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render partial: "show", locals: { header: "Recorded by", name: @media.artist } %> |
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.
We can DRY this out a bit by making this line into a
before_action
, because it is used to setup the@media
variable the same way in multiple controller actions.