-
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 Waves1-3 #44
base: ash/master
Are you sure you want to change the base?
Changes from all commits
44e326b
bb296a7
881f8b9
e2c99e4
e0ae8ba
88f584f
955f630
523560f
b15208e
c36c240
0cb5157
35533da
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 |
---|---|---|
@@ -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,55 @@ | ||
class AlbumsController < ApplicationController | ||
def index | ||
@albums = Album.all | ||
end | ||
|
||
def show | ||
@album = Album.find(params[:id]) | ||
end | ||
|
||
def edit | ||
@album = Album.find(params[:id]) | ||
end | ||
|
||
def new | ||
@album = Album.new | ||
end | ||
|
||
def create | ||
@album = Album.new(album_params) | ||
if @album.save | ||
redirect_to albums_path | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
id = params[:id] | ||
album = Album.find(id) | ||
album.update_attributes(album_params) | ||
redirect_to album_path(params[:id]) | ||
end | ||
|
||
def destroy | ||
Album.destroy(params[:id]) | ||
redirect_to albums_path | ||
end | ||
|
||
def upvote | ||
id = params[:id] | ||
@album = Album.find(id) | ||
if @album.rank.nil? | ||
@album.rank = 0 | ||
end | ||
@album.rank += 1 | ||
@album.save | ||
render "show" | ||
end | ||
|
||
private | ||
|
||
def album_params | ||
params.require(:album).permit(:name, :artist, :description, :rank) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class BooksController < ApplicationController | ||
def index | ||
@books = Book.all | ||
end | ||
|
||
def show | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def edit | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def new | ||
@book = Book.new | ||
end | ||
|
||
def create | ||
@book = Book.new(book_params) | ||
if @book.save | ||
redirect_to books_path | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
id = params[:id] | ||
book = Book.find(id) | ||
book.update_attributes(book_params) | ||
redirect_to book_path(params[:id]) | ||
end | ||
|
||
def destroy | ||
Book.destroy(params[:id]) | ||
redirect_to books_path | ||
end | ||
|
||
def upvote | ||
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. Since the logic in this method is affecting the object, it would be more appropriate as a model method which you then call from the controller. |
||
id = params[:id] | ||
@book = Book.find(id) | ||
if @book.rank.nil? | ||
@book.rank = 0 | ||
end | ||
@book.rank += 1 | ||
@book.save | ||
render "show" | ||
end | ||
|
||
private | ||
|
||
def book_params | ||
params.require(:book).permit(:name, :author, :description, :rank) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class MoviesController < ApplicationController | ||
def index | ||
@movies = Movie.all | ||
end | ||
|
||
def show | ||
@movie = Movie.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. You can extract |
||
end | ||
|
||
def edit | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def new | ||
@movie = Movie.new | ||
end | ||
|
||
def create | ||
@movie = Movie.new(movie_params) | ||
if @movie.save | ||
redirect_to movies_path | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
id = params[:id] | ||
movie = Movie.find(id) | ||
movie.update_attributes(movie_params) | ||
redirect_to movie_path(params[:id]) | ||
end | ||
|
||
def destroy | ||
Movie.destroy(params[:id]) | ||
redirect_to movies_path | ||
end | ||
|
||
def upvote | ||
id = params[:id] | ||
@movie = Movie.find(id) | ||
if @movie.rank.nil? | ||
@movie.rank = 0 | ||
end | ||
@movie.rank += 1 | ||
@movie.save | ||
render "show" | ||
end | ||
|
||
private | ||
|
||
def movie_params | ||
params.require(:movie).permit(:name, :director, :description, :rank) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class WelcomeController < ApplicationController | ||
def home | ||
@movies= Movie.all | ||
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. Small nitpick for code readability: leave a space between the instance variable and the equals sign, like: @movies = Movie.all If you guys haven't seen it yet, this style guide is pretty standard. |
||
@albums= Album.all | ||
@books= Book.all | ||
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,4 @@ | ||
class Album < ActiveRecord::Base | ||
validates :name, presence: true | ||
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 job validating your data in the model. |
||
validates :name, uniqueness: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Book < ActiveRecord::Base | ||
validates :name, presence: true | ||
validates :name, uniqueness: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Movie < ActiveRecord::Base | ||
validates :name, presence: true | ||
validates :name, uniqueness: 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.
Since you use this line several times, you can DRY up your code by extracting it into a separate private method and calling that method instead. You can then also set it up as a before action scoped to show, edit, and update. Eg.