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

Lrg/master #38

Open
wants to merge 21 commits into
base: lrg/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
3 changes: 2 additions & 1 deletion media-ranker/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ gem 'rails', '4.2.5'
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use bootstrap for styling
gem 'bootstrap-sass', '~> 3.3.6'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
Expand Down Expand Up @@ -39,7 +41,6 @@ group :development, :test do
gem 'simplecov'
gem 'better_errors'
gem 'binding_of_caller'
gem 'rails-erd'
end

group :development do
Expand Down
15 changes: 7 additions & 8 deletions media-ranker/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ 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)
coderay (1.1.0)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -100,11 +105,6 @@ GEM
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-erd (1.4.4)
activerecord (>= 3.2)
activesupport (>= 3.2)
choice (~> 0.2.0)
ruby-graphviz (~> 1.2)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
railties (4.2.5)
Expand All @@ -131,7 +131,6 @@ GEM
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)
railties (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -177,12 +176,12 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
rails (= 4.2.5)
rails-erd
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
Expand Down
Binary file added media-ranker/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 media-ranker/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 media-ranker/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 media-ranker/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 media-ranker/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 media-ranker/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,12 @@
* 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
*/

@import "bootstrap-sprockets";
@import "bootstrap";

.page-header {
background: url(/assets/images/owl.jpg);
background-repeat: no-repeat;
}
3 changes: 3 additions & 0 deletions media-ranker/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 media-ranker/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/
50 changes: 50 additions & 0 deletions media-ranker/app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class AlbumsController < ApplicationController

def index
@albums = Album.order(rank: :desc)
end

def create
album = Album.create(album_params)
album.update_attribute(:rank, 1)
redirect_to albums_path
Copy link

Choose a reason for hiding this comment

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

ℹ️ Be sure to check out polymorphic paths and see if you know how you could implement them. They're perfectly suited for this project.

end

def new
@album = Album.new
end

def edit
@album = Album.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 basically all these controllers' methods require @media = Media.find(params[:id]), using a before_action in each controller could clean things up a little.

end

def show
@album = Album.find(params[:id])
end

def update
album = Album.find(params[:id])
album.update(album_params)
redirect_to albums_path
end

def destroy
album = Album.find(params[:id])
album.destroy
redirect_to albums_path
end

def upvote
album = Album.find(params[:id])
rank = album.rank + 1
album.update_attribute(:rank, rank)
Copy link

Choose a reason for hiding this comment

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

👍 There's also a cool .increment! method that does the same thing as lines 39-40.

redirect_to(:back)
end

private

def album_params
params.require(:album).permit(:title, :artist, :description)
end

end
9 changes: 7 additions & 2 deletions media-ranker/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
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

def index
@books = Book.order(rank: :desc).limit(3)
@albums = Album.order(rank: :desc).limit(3)
@movies = Movie.order(rank: :desc).limit(3)
Copy link

Choose a reason for hiding this comment

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

This 3 is a "magic number" -- a variable determined more or less arbitrarily and could easily change in the future. Suddenly the client wants the top 5! If this theme of 3 things was repeated elsewhere in the application it would be handy to store it as a constant so you only have to change it in one place.

end

end
50 changes: 50 additions & 0 deletions media-ranker/app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class BooksController < ApplicationController
Copy link

Choose a reason for hiding this comment

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

Same comments as Albums controller.


def index
@books = Book.order(rank: :desc)
end

def create
book = Book.create(book_params)
book.update_attribute(:rank, 1)
redirect_to books_path
end

def new
@book = Book.new
end

def edit
@book = Book.find(params[:id])
end

def show
@book = Book.find(params[:id])
end

def update
book = Book.find(params[:id])
book.update(book_params)
redirect_to books_path
end

def destroy
book = Book.find(params[:id])
book.destroy
redirect_to books_path
end

def upvote
book = Book.find(params[:id])
rank = book.rank + 1
book.update_attribute(:rank, rank)
redirect_to(:back)
end

private

def book_params
params.require(:book).permit(:title, :author, :description)
end

end
50 changes: 50 additions & 0 deletions media-ranker/app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class MoviesController < ApplicationController
Copy link

Choose a reason for hiding this comment

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

Same comments as Albums controller.


def index
@movies = Movie.order(rank: :desc)
end

def create
movie = Movie.create(movie_params)
movie.update_attribute(:rank, 1)
redirect_to movies_path
end

def new
@movie = Movie.new
end

def edit
@movie = Movie.find(params[:id])
end

def show
@movie = Movie.find(params[:id])
end

def update
movie = Movie.find(params[:id])
movie.update(movie_params)
redirect_to movies_path
end

def destroy
movie = Movie.find(params[:id])
movie.destroy
redirect_to movies_path
end

def upvote
movie = Movie.find(params[:id])
rank = movie.rank + 1
movie.update_attribute(:rank, rank)
redirect_to(:back)
end

private

def movie_params
params.require(:movie).permit(:title, :director, :description)
end

end
2 changes: 2 additions & 0 deletions media-ranker/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 media-ranker/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 media-ranker/app/helpers/movies_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MoviesHelper
end
5 changes: 5 additions & 0 deletions media-ranker/app/models/album.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Album < ActiveRecord::Base
validates :title, presence: true;
validates :artist, presence: true;
validates :description, presence: true;
end
5 changes: 5 additions & 0 deletions media-ranker/app/models/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Book < ActiveRecord::Base
validates :title, presence: true;
validates :author, presence: true;
validates :description, presence: true;
end
5 changes: 5 additions & 0 deletions media-ranker/app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Movie < ActiveRecord::Base
validates :title, presence: true;
validates :director, presence: true;
validates :description, presence: true;
end
14 changes: 14 additions & 0 deletions media-ranker/app/views/albums/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="col-lg-12">
<h2>Edit Album</h2>
Copy link

Choose a reason for hiding this comment

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

You might be able to create a shared form for editing any media type, and likewise for creating any media type.

<%= form_for @album do |f| %>
<div class="form-group">
<%= f.label :title %>
<%= f.text_field :title, class: "form-control" %>
<%= f.label :artist %>
<%= f.text_field :artist, class: "form-control" %>
<%= f.label :description %>
<%= f.text_area :description, class: "form-control" %>
</div>
<%= f.submit "Save", class: "btn btn-default" %>
<% end %>
</div>
21 changes: 21 additions & 0 deletions media-ranker/app/views/albums/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="row">
<div class="col-lg-12">
<table class="table table-hover">
<thead>
<th>Ranking</th>
<th>Name</th>
<th>Upvote</th>
</thead>
<tbody>
<% @albums.each do |album| %>
<tr>
<td>Ranked: <%= album.rank%></td>
<td><%= link_to album.title, album_path(album.id) %></td>
<td><%= button_to 'Upvote', upvote_album_path(album.id), class: 'btn btn-default' %></td>
</tr>
<% end %>
</tbody>
</table>
<%= button_to 'View All Media', root_path, :method => :get, class: 'btn btn-default' %> <%= button_to 'Add An Ablum ', new_album_path , :method => :get, class: 'btn btn-default' %>
</div>
</div>
14 changes: 14 additions & 0 deletions media-ranker/app/views/albums/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="col-lg-12">
<h2>New Album</h2>
<%= form_for @album do |f| %>
<div class="form-group">
<%= f.label :title %>
<%= f.text_field :title, class: "form-control" %>
<%= f.label :artist %>
<%= f.text_field :artist, class: "form-control" %>
<%= f.label :description %>
<%= f.text_area :description, class: "form-control" %>
</div>
<%= f.submit "Save", class: "btn btn-default" %>
<% end %>
</div>
12 changes: 12 additions & 0 deletions media-ranker/app/views/albums/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="col-lg-12">
<h1><%= @album.title %> <small>Recorded by: <%= @album.artist %></small></h1>
<h4>Ranked: <%= @album.rank %></h4>
<p>
<%= @album.description %>
</p>
<%= button_to 'Upvote', upvote_album_path(@album.id), class: "btn btn-primary" %>
<%= button_to "Edit #{@album.title}", edit_album_path(@album.id) , :method => :get, class: "btn btn-default" %>
<%= button_to 'Delete', album_path, :method => :delete, class: "btn btn-danger" %>
<%= button_to 'View All albums', albums_path, :method => :get, class: "btn btn-default" %>
<%= button_to 'View All Media', root_path, :method => :get, class: "btn btn-default" %>
</div>
Loading