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 by Becca #35

Open
wants to merge 21 commits into
base: RmT/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b8b2837
generated models and controllers for all media
rmtolmach Nov 30, 2015
fe4eacf
migrated, added schema
rmtolmach Nov 30, 2015
ae5845a
created page to make a new movie and a show page to display it. Also …
rmtolmach Nov 30, 2015
a58fa48
page to make new book and show page to display it
rmtolmach Nov 30, 2015
b6982d4
page to make new album and show page to display it
rmtolmach Dec 1, 2015
4562328
added 'rank' to schema and edit functionality is working for books
rmtolmach Dec 1, 2015
c186177
can update movies and albums
rmtolmach Dec 1, 2015
5477bb2
added spec folder and files and 'stubs'
rmtolmach Dec 1, 2015
da6982e
14 tests passing for books
rmtolmach Dec 1, 2015
2011d4e
copied specs for other controllers. 21 working, 100% coverage
rmtolmach Dec 2, 2015
7ef4cbd
created blank index page and action for all media
rmtolmach Dec 2, 2015
d537e79
installed bootstrap and it's working
rmtolmach Dec 2, 2015
92ad20b
index page for all media is functional.
rmtolmach Dec 2, 2015
d7b661a
added tests for index file (woops, should have written tests first)
rmtolmach Dec 2, 2015
5fec1fe
delete tests, actions and front-end working. yay
rmtolmach Dec 2, 2015
d63c719
Index page just showing 10 of each
rmtolmach Dec 3, 2015
d010e3f
index page is fully functional
rmtolmach Dec 3, 2015
a48b57f
upvote botton working correctly
rmtolmach Dec 3, 2015
9c71175
test for upvote button working.
rmtolmach Dec 3, 2015
e5a0e73
users are rerouted to edit page if they don't put in a name. links ad…
rmtolmach Dec 4, 2015
776f1c8
added divs for bootstrap styling
rmtolmach Dec 4, 2015
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
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
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ source 'https://rubygems.org'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# for bootstrap magic
gem 'bootstrap-sass', '~> 3.3.6'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
Expand Down Expand Up @@ -35,6 +37,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'rspec-rails'
gem 'simplecov', :require => false
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 @@ -113,6 +121,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 @@ -124,6 +149,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
simplecov (0.11.0)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
spring (1.5.0)
sprockets (3.4.1)
rack (> 1, < 3)
Expand Down Expand Up @@ -154,15 +184,18 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
bootstrap-sass (~> 3.3.6)
byebug
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
pg
rails (= 4.2.5)
rails-erd
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simplecov
spring
sqlite3
turbolinks
Expand Down
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,15 @@
* 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-image: url(http://media-ranker.herokuapp.com/assets/owl-5e51d9e0d49c787f2ebd143e32cbf41c.jpg);
background-repeat: no-repeat;
}

.page-header h1 {
margin-left: 150px;
}
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/
63 changes: 63 additions & 0 deletions app/controllers/albums_controller.rb
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)

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 as rank: 0

if @album.save
redirect_to album_path(@album.id)
else
render "new"
end

end

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

Choose a reason for hiding this comment

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

Since you repeat @album = Album.find(params[:id]) on several actions, you can use a before_action to set this and DRY up your code.

end

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

def update
@album = Album.find(params[:id])
@album.update_attributes(album_params)
if @album.save

Choose a reason for hiding this comment

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

Instead of using #update_attributes and then doing if @album.save on the following line, you can combine these with if @album.update(album_params).

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"

Choose a reason for hiding this comment

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

Personal preference: I like the :edit syntax better. Totally up to you.

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

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

Line 47 and 48 could be combined to rank = album.rank + 1

album.update(rank: rank)
redirect_to :back
end



###########PRIVATE############
private

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

Choose a reason for hiding this comment

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

Nice use of require and permit!

end


end
59 changes: 59 additions & 0 deletions app/controllers/books_controller.rb
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
62 changes: 62 additions & 0 deletions app/controllers/movies_controller.rb
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
9 changes: 9 additions & 0 deletions app/controllers/welcome_controller.rb
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
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

Choose a reason for hiding this comment

The 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.

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
3 changes: 3 additions & 0 deletions app/models/album.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Album < ActiveRecord::Base
validates :name, presence: true
end
3 changes: 3 additions & 0 deletions app/models/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Book < ActiveRecord::Base
validates :name, presence: true
end
3 changes: 3 additions & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Movie < ActiveRecord::Base
validates :name, presence: true
end
15 changes: 15 additions & 0 deletions app/views/albums/edit.html.erb
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| %>

Choose a reason for hiding this comment

The 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 url: {action: "update"} is required. Usually the Rails form_for can infer whether it's an update or create based on whether @album is a new object, or if it's an already-existing object.


<%= 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 %>
Loading