-
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 by Becca #35
base: RmT/master
Are you sure you want to change the base?
Changes from all commits
b8b2837
fe4eacf
ae5845a
a58fa48
b6982d4
4562328
c186177
5477bb2
da6982e
2011d4e
7ef4cbd
d537e79
92ad20b
d7b661a
5fec1fe
d63c719
d010e3f
a48b57f
9c71175
e5a0e73
776f1c8
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,63 @@ | ||
class AlbumsController < ApplicationController | ||
|
||
def index | ||
@albums = Album.all | ||
end | ||
|
||
def new | ||
@album = Album.new | ||
end | ||
|
||
def create | ||
@album = Album.create(album_params) | ||
@album.update(:rank => 0) | ||
if @album.save | ||
redirect_to album_path(@album.id) | ||
else | ||
render "new" | ||
end | ||
|
||
end | ||
|
||
def show | ||
@album = Album.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. Since you repeat |
||
end | ||
|
||
def edit | ||
@album = Album.find(params[:id]) | ||
end | ||
|
||
def update | ||
@album = Album.find(params[:id]) | ||
@album.update_attributes(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. Instead of using However, I suppose if you want the updates to show on the edit view, what you have is better :) |
||
redirect_to album_path(params[:id]) | ||
else | ||
render "edit" | ||
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. Personal preference: I like the 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. Another option is to redirect_to the edit action. There are some tradeoffs, though, like not being able to show the updated attributes. Personally, I like your way better. |
||
end | ||
end | ||
|
||
def destroy | ||
Album.destroy(params[:id]) | ||
redirect_to albums_path | ||
end | ||
|
||
def upvote | ||
album = Album.find(params[:id]) | ||
rank = album.rank | ||
rank += 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. Line 47 and 48 could be combined to |
||
album.update(rank: rank) | ||
redirect_to :back | ||
end | ||
|
||
|
||
|
||
###########PRIVATE############ | ||
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 require and permit! |
||
end | ||
|
||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
class BooksController < ApplicationController | ||
|
||
def index | ||
@books = Book.all | ||
end | ||
|
||
def new | ||
@book = Book.new | ||
end | ||
|
||
def create | ||
@book = Book.create(book_params) | ||
@book.update(:rank => 0) | ||
if @book.save | ||
redirect_to book_path(@book.id) | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def show | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def edit | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
def update | ||
@book = Book.find(params[:id]) | ||
@book.update_attributes(book_params) | ||
if @book.save | ||
redirect_to book_path(params[:id]) | ||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
Book.destroy(params[:id]) | ||
redirect_to books_path | ||
end | ||
|
||
def upvote | ||
book = Book.find(params[:id]) | ||
rank = book.rank | ||
rank += 1 | ||
book.update(rank: rank) | ||
redirect_to :back | ||
end | ||
|
||
|
||
#############PRIVATE########### | ||
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,62 @@ | ||
class MoviesController < ApplicationController | ||
|
||
def index | ||
@movies = Movie.all | ||
end | ||
|
||
def new | ||
@movie = Movie.new | ||
end | ||
|
||
def create | ||
@movie = Movie.create(movie_params) | ||
@movie.update(:rank => 0) | ||
if @movie.save | ||
redirect_to movie_path(@movie.id) | ||
else | ||
render "new" | ||
end | ||
|
||
end | ||
|
||
def show | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def edit | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def update | ||
@movie = Movie.find(params[:id]) | ||
@movie.update_attributes(movie_params) | ||
if @movie.save | ||
redirect_to movie_path(params[:id]) | ||
else | ||
render "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
Movie.destroy(params[:id]) | ||
redirect_to movies_path | ||
end | ||
|
||
def upvote | ||
movie = Movie.find(params[:id]) | ||
rank = movie.rank | ||
rank += 1 | ||
movie.update(rank: rank) | ||
redirect_to :back | ||
end | ||
|
||
|
||
|
||
###########PRIVATE############ | ||
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,9 @@ | ||
class WelcomeController < ApplicationController | ||
|
||
def index | ||
@movies = Movie.all.order(rank: :desc) | ||
@books = Book.all.order(rank: :desc) | ||
@albums = Album.all.order(rank: :desc) | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AlbumsHelper | ||
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. Depending on who you ask, some people feel strongly about deleting the auto-generated files that you don't use. It's not a big deal, though, and maybe not worth your time. |
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,15 @@ | ||
<h3>Edit Album</h3> | ||
|
||
<%= form_for @album, url: {action: "update"}, html: {class: "edit-album"} do |f| %> | ||
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. It's been a while so I could be wrong, but I don't think |
||
|
||
<%= f.label :name, "Name" %> | ||
<%= f.text_field :name %> | ||
|
||
<%= f.label :artist, "Artist" %> | ||
<%= f.text_field :artist %> | ||
|
||
<%= f.label :description, "Description" %> | ||
<%= f.text_area :description %> | ||
|
||
<%= f.submit "Save" %> | ||
<% 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.
To save yourself some typing,
:rank => 0
can also be written asrank: 0