Skip to content
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

Open
wants to merge 12 commits into
base: ash/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
Expand Down Expand Up @@ -36,6 +37,8 @@ group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'pry'
gem 'rspec-rails'
gem 'simplecov'
end

group :development do
Expand Down
33 changes: 33 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
autoprefixer-rails (6.1.2)
execjs
json
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.6)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2)
byebug (8.2.1)
choice (0.2.0)
Expand All @@ -55,6 +61,8 @@ GEM
execjs
coffee-script-source (1.10.0)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
docile (1.1.5)
erubis (2.7.0)
execjs (2.6.0)
globalid (0.3.6)
Expand Down Expand Up @@ -117,6 +125,23 @@ GEM
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rdoc (4.2.0)
rspec-core (3.4.1)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-rails (3.4.0)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
ruby-graphviz (1.2.2)
sass (3.4.19)
sass-rails (5.0.4)
Expand All @@ -128,6 +153,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
simplecov (0.11.1)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
spring (1.5.0)
sprockets (3.4.1)
Expand Down Expand Up @@ -159,15 +189,18 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
pry
rails (= 4.2.5)
rails-erd
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simplecov
spring
sqlite3
turbolinks
Expand Down
Binary file added app/.DS_Store
Binary file not shown.
Binary file added app/assets/.DS_Store
Binary file not shown.
Binary file added app/assets/images/.DS_Store
Binary file not shown.
Binary file added app/assets/images/owl.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/albums.coffee
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/
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// about supported directives.
//
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require_tree .
3 changes: 3 additions & 0 deletions app/assets/javascripts/books.coffee
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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/movies.coffee
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/
3 changes: 3 additions & 0 deletions app/assets/javascripts/welcome.coffee
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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/albums.scss
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
Expand Up @@ -10,6 +10,32 @@
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self

*/
// "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"
@import "bootstrap-sprockets";
@import "bootstrap";

a{
color: #428bca;
}

form .btn-primary {
margin-bottom: 10px;
}

.page-header {
background-image: image-url("owl.jpg");
background-repeat: no-repeat;
padding-bottom: 9px;
margin: 40px 0 20px;
border-bottom: 1px solid #eee;
}

.page-header h1 {
margin-left: 150px;
}

div {
display: block;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/books.scss
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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/movies.scss
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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/welcome.scss
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/
55 changes: 55 additions & 0 deletions app/controllers/albums_controller.rb
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
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

end
55 changes: 55 additions & 0 deletions app/controllers/books_controller.rb
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])
Copy link

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.

before_action: find_book, only: [:show, :edit, :update]

private

def find_book
  return Book.find(params[:id])
end

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
Copy link

Choose a reason for hiding this comment

The 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
55 changes: 55 additions & 0 deletions app/controllers/movies_controller.rb
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])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extract find_movie here as in BooksController.

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
7 changes: 7 additions & 0 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class WelcomeController < ApplicationController
def home
@movies= Movie.all
Copy link

Choose a reason for hiding this comment

The 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
2 changes: 2 additions & 0 deletions app/helpers/albums_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AlbumsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/books_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BooksHelper
end
2 changes: 2 additions & 0 deletions app/helpers/movies_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MoviesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/welcome_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module WelcomeHelper
end
4 changes: 4 additions & 0 deletions app/models/album.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Album < ActiveRecord::Base
validates :name, presence: true
Copy link

Choose a reason for hiding this comment

The 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
4 changes: 4 additions & 0 deletions app/models/book.rb
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
4 changes: 4 additions & 0 deletions app/models/movie.rb
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
Loading