diff --git a/.gitignore b/.gitignore index 050c9d95c7..b4c3142267 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,40 @@ /log/* !/log/.keep /tmp + +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +## Specific to RubyMotion: +.dat* +.repl_history +build/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalisation: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc diff --git a/Gemfile b/Gemfile index c6bd1caafb..1d2cd4c15c 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ source 'https://rubygems.org' gem 'rails', '4.2.5' # Use sqlite3 as the database for Active Record gem 'sqlite3' +gem 'bootstrap-sass', '~> 3.3.6' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets @@ -35,6 +36,10 @@ 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 'binding_of_caller' + gem 'pry' + gem 'simplecov' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index fb94889cd0..538b71e2fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -72,12 +80,17 @@ GEM nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) + method_source (0.8.2) mime-types (2.99) mini_portile2 (2.0.0) minitest (5.8.3) multi_json (1.11.2) nokogiri (1.6.7) mini_portile2 (~> 2.0.0.rc2) + pry (0.10.3) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) @@ -112,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) @@ -123,6 +153,12 @@ 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) + slop (3.6.0) spring (1.5.0) sprockets (3.4.1) rack (> 1, < 3) @@ -153,14 +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 diff --git a/app/assets/images/owl.jpg b/app/assets/images/owl.jpg new file mode 100644 index 0000000000..b3ded30950 Binary files /dev/null and b/app/assets/images/owl.jpg differ diff --git a/app/assets/javascripts/albums.coffee b/app/assets/javascripts/albums.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/albums.coffee @@ -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/ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e07c5a830f..f91cae5d9b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,6 +11,7 @@ // about supported directives. // //= require jquery +//= require bootstrap-sprockets //= require jquery_ujs //= require turbolinks //= require_tree . diff --git a/app/assets/javascripts/books.coffee b/app/assets/javascripts/books.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/books.coffee @@ -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/ diff --git a/app/assets/javascripts/movies.coffee b/app/assets/javascripts/movies.coffee new file mode 100644 index 0000000000..24f83d18bb --- /dev/null +++ b/app/assets/javascripts/movies.coffee @@ -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/ diff --git a/app/assets/stylesheets/albums.scss b/app/assets/stylesheets/albums.scss new file mode 100644 index 0000000000..684cc4c17f --- /dev/null +++ b/app/assets/stylesheets/albums.scss @@ -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/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 65% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index f9cd5b3483..602789ba11 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -10,6 +10,20 @@ * 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"; + + form .btn-primary { + margin-bottom: 10px; + } + + .page-header { + background-image: url(/assets/owl.jpg); + background-repeat: no-repeat; + } + + .page-header h1 { + margin-left: 150px; + } diff --git a/app/assets/stylesheets/books.scss b/app/assets/stylesheets/books.scss new file mode 100644 index 0000000000..9fab565c8d --- /dev/null +++ b/app/assets/stylesheets/books.scss @@ -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/ diff --git a/app/assets/stylesheets/movies.scss b/app/assets/stylesheets/movies.scss new file mode 100644 index 0000000000..b86dfedb53 --- /dev/null +++ b/app/assets/stylesheets/movies.scss @@ -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/ diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb new file mode 100644 index 0000000000..e508c76f93 --- /dev/null +++ b/app/controllers/albums_controller.rb @@ -0,0 +1,61 @@ +class AlbumsController < ApplicationController + before_action :find_media, except: [:index, :new, :create] + + def index + @media = Album.order(ranking: :desc) + end + + def show + end + + def new + @media = Album.new + end + + def create + @media = Album.new(strong_params) + @media.ranking = 0 + if @media.save + render "show" + else + render "new" + end + end + + def edit + end + + def update + @media.attributes = strong_params + if @media.save + render "show" + else + render "edit" + end + end + + def destroy + @media.destroy + redirect_to albums_path + end + + def upvote + @media.ranking += 1 + @media.save + render "show" + end + + private + + def strong_params + params.require(:album).permit(:name, :artist, :description) + end + + def find_media + if params[:id].nil? + @media = Album.find(params[:album_id]) + else + @media = Album.find(params[:id]) + end + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e1b9..9176ae247f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,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 + @movies = Movie.order(ranking: :desc).limit(2) + @books = Book.order(ranking: :desc).limit(2) + @albums = Album.order(ranking: :desc).limit(2) + end end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000000..fb7611b66f --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,61 @@ +class BooksController < ApplicationController + before_action :find_media, except: [:index, :new, :create] + + def index + @media = Book.order(ranking: :desc) + end + + def show + end + + def new + @media = Book.new + end + + def create + @media = Book.new(strong_params) + @media.ranking = 0 + if @media.save + render "show" + else + render "new" + end + end + + def edit + end + + def update + @media.attributes = strong_params + if @media.save + render "show" + else + render "edit" + end + end + + def destroy + @media.destroy + redirect_to books_path + end + + def upvote + @media.ranking += 1 + @media.save + render "show" + end + + private + + def strong_params + params.require(:book).permit(:name, :author, :description) + end + + def find_media + if params[:id].nil? + @media = Book.find(params[:book_id]) + else + @media = Book.find(params[:id]) + end + end +end diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 0000000000..363759ae9d --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,61 @@ +class MoviesController < ApplicationController + before_action :find_media, except: [:index, :new, :create] + + def index + @media = Movie.order(ranking: :desc) + end + + def show + end + + def new + @media = Movie.new + end + + def create + @media = Movie.new(strong_params) + @media.ranking = 0 + if @media.save + render "show" + else + render "new" + end + end + + def edit + end + + def update + @media.attributes = strong_params + if @media.save + render "show" + else + render "edit" + end + end + + def destroy + @media.destroy + redirect_to movies_path + end + + def upvote + @media.ranking += 1 + @media.save + render "show" + end + + private + + def strong_params + params.require(:movie).permit(:name, :director, :description) + end + + def find_media + if params[:id].nil? + @media = Movie.find(params[:movie_id]) + else + @media = Movie.find(params[:id]) + end + end +end diff --git a/app/helpers/albums_helper.rb b/app/helpers/albums_helper.rb new file mode 100644 index 0000000000..d976b7cef8 --- /dev/null +++ b/app/helpers/albums_helper.rb @@ -0,0 +1,2 @@ +module AlbumsHelper +end diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb new file mode 100644 index 0000000000..4b9311e0be --- /dev/null +++ b/app/helpers/books_helper.rb @@ -0,0 +1,2 @@ +module BooksHelper +end diff --git a/app/helpers/movies_helper.rb b/app/helpers/movies_helper.rb new file mode 100644 index 0000000000..493eee555f --- /dev/null +++ b/app/helpers/movies_helper.rb @@ -0,0 +1,2 @@ +module MoviesHelper +end diff --git a/app/models/album.rb b/app/models/album.rb new file mode 100644 index 0000000000..b965f608d0 --- /dev/null +++ b/app/models/album.rb @@ -0,0 +1,3 @@ +class Album < ActiveRecord::Base + validates :name, presence: true +end diff --git a/app/models/book.rb b/app/models/book.rb new file mode 100644 index 0000000000..7b27cc85bd --- /dev/null +++ b/app/models/book.rb @@ -0,0 +1,3 @@ +class Book < ActiveRecord::Base + validates :name, presence: true +end diff --git a/app/models/movie.rb b/app/models/movie.rb new file mode 100644 index 0000000000..02e279fc1c --- /dev/null +++ b/app/models/movie.rb @@ -0,0 +1,3 @@ +class Movie < ActiveRecord::Base + validates :name, presence: true +end diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb new file mode 100644 index 0000000000..de58e0c11f --- /dev/null +++ b/app/views/albums/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: 'form', locals: { type: "Edit", media: "Album" } %> diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb new file mode 100644 index 0000000000..6ce9337333 --- /dev/null +++ b/app/views/albums/index.html.erb @@ -0,0 +1 @@ +<%= render partial: "index", locals: { class_type: Album } %> diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb new file mode 100644 index 0000000000..78446830cb --- /dev/null +++ b/app/views/albums/new.html.erb @@ -0,0 +1 @@ +<%= render partial: 'form', locals: { type: "Create", media: "Album" } %> diff --git a/app/views/albums/show.html.erb b/app/views/albums/show.html.erb new file mode 100644 index 0000000000..be03501103 --- /dev/null +++ b/app/views/albums/show.html.erb @@ -0,0 +1 @@ +<%= render partial: "show", locals: { header: "Recorded by", name: @media.artist } %> diff --git a/app/views/application/_form.html.erb b/app/views/application/_form.html.erb new file mode 100644 index 0000000000..c6ea5fd03d --- /dev/null +++ b/app/views/application/_form.html.erb @@ -0,0 +1,30 @@ +
| Ranking | +Name | +Upvote | +
|---|---|---|
| Ranked: <%= media.ranking %> | +<%= link_to media.name, polymorphic_path(media) %> | +<%= button_to "Upvote", polymorphic_path([media, :upvote]), + :method => :patch, class: "btn btn-default" %> | +
<%= @media.description %>
+ +<%= button_to "Upvote", polymorphic_path([@media, :upvote]), + :method => :patch, class: "btn btn-primary" %> + +<%= link_to "Edit #{@media.name}", edit_polymorphic_path(@media), class: "btn btn-default" %> + +<%= link_to "DELETE", polymorphic_path(@media), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> + +<%= link_to "View All #{@media.class}s", polymorphic_path(@media.class), class: "btn btn-default" %> + +<%= link_to "View All Media", root_path, class: "btn btn-default" %> +