diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000..2430a8ac7b --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +STRIPE_PUBLISHABLE_KEY=your_test_key_here +STRIPE_SECRET_KEY=your_test_key_here diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..f567897479 --- /dev/null +++ b/.gitignore @@ -0,0 +1,57 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore all logfiles and tempfiles. +/log/* +!/log/.keep +/tmp + +# Ignore carrier wave uploads for development +/public/uploads + +# Ignore db creds / settings +/config/database.yml + +*.rbc +capybara-*.html +.rspec +/db/*.sqlite3 +/db/*.sqlite3-journal +/public/system +/coverage/ +/spec/tmp +**.orig +rerun.txt +pickle-email-*.html + +# TODO Comment out these rules if you are OK with secrets being uploaded to the repo +config/initializers/secret_token.rb +config/secrets.yml + +# dotenv +# TODO Comment out this rule if environment variables can be committed +.env + +## Environment normalization: +/.bundle +/vendor/bundle + +# these should all be checked in to normalize the environment: +# Gemfile.lock, .ruby-version, .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# if using bower-rails ignore default bower_components path bower.json files +/vendor/assets/bower_components +*.bowerrc +bower.json + +# Ignore pow environment settings +.powenv + +# Ignore Byebug command history file. +.byebug_history diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..b9d0803beb --- /dev/null +++ b/Gemfile @@ -0,0 +1,60 @@ +source 'https://rubygems.org' +ruby "2.3.0" + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.2.6' +# Use postgresql as the database for Active Record +gem 'pg' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# Use CoffeeScript for .coffee assets and views +# gem 'coffee-rails', '~> 4.1.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'therubyracer', platforms: :ruby + +# Use jquery as the JavaScript library +gem 'jquery-rails' +# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks +gem 'turbolinks' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.0' +# bundle exec rake doc:rails generates the API under doc/api. +gem 'sdoc', '~> 0.4.0', group: :doc + +# Use ActiveModel has_secure_password +gem 'bcrypt', '~> 3.1.7' + +gem 'puma' + +gem 'bootstrap-sass', '~> 3.3.6' +gem 'font-awesome-rails' +gem 'money-rails' +gem 'carrierwave' +gem 'rmagick' +gem 'stripe' +gem 'faker' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug' + gem 'quiet_assets' + gem 'dotenv-rails' +end + +group :development do + # Access an IRB console on exception pages or by using <%= console %> in views + gem 'web-console', '~> 2.0' + + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' +end + +group :production do + gem 'newrelic_rpm' + gem 'rails_12factor' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..17abe4a12f --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,219 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.2.6) + actionpack (= 4.2.6) + actionview (= 4.2.6) + activejob (= 4.2.6) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.6) + actionview (= 4.2.6) + activesupport (= 4.2.6) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.6) + activesupport (= 4.2.6) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.6) + activesupport (= 4.2.6) + globalid (>= 0.3.0) + activemodel (4.2.6) + activesupport (= 4.2.6) + builder (~> 3.1) + activerecord (4.2.6) + activemodel (= 4.2.6) + activesupport (= 4.2.6) + arel (~> 6.0) + activesupport (4.2.6) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + arel (6.0.3) + autoprefixer-rails (6.3.7) + execjs + bcrypt (3.1.11) + 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 (9.0.5) + carrierwave (0.10.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) + concurrent-ruby (1.0.2) + debug_inspector (0.0.2) + domain_name (0.5.20160615) + unf (>= 0.0.5, < 1.0.0) + dotenv (1.0.2) + dotenv-rails (1.0.2) + dotenv (= 1.0.2) + erubis (2.7.0) + execjs (2.7.0) + faker (1.6.1) + i18n (~> 0.5) + font-awesome-rails (4.5.0.1) + railties (>= 3.2, < 5.1) + globalid (0.3.6) + activesupport (>= 4.1.0) + http-cookie (1.0.2) + domain_name (~> 0.5) + i18n (0.7.0) + jbuilder (2.6.0) + activesupport (>= 3.0.0, < 5.1) + multi_json (~> 1.2) + jquery-rails (4.1.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (1.8.3) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.9.0) + monetize (1.1.0) + money (~> 6.5.0) + money (6.5.1) + i18n (>= 0.6.4, <= 0.7.0) + money-rails (1.4.1) + activesupport (>= 3.0) + monetize (~> 1.1.0) + money (~> 6.5.0) + railties (>= 3.0) + multi_json (1.12.1) + netrc (0.11.0) + newrelic_rpm (3.16.0.318) + nokogiri (1.6.8) + mini_portile2 (~> 2.1.0) + pkg-config (~> 1.1.7) + pg (0.18.4) + pkg-config (1.1.7) + puma (3.5.2) + quiet_assets (1.0.3) + railties (>= 3.1, < 5.0) + rack (1.6.4) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.2.6) + actionmailer (= 4.2.6) + actionpack (= 4.2.6) + actionview (= 4.2.6) + activejob (= 4.2.6) + activemodel (= 4.2.6) + activerecord (= 4.2.6) + activesupport (= 4.2.6) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.6) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + rails_12factor (0.0.3) + rails_serve_static_assets + rails_stdout_logging + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) + railties (4.2.6) + actionpack (= 4.2.6) + activesupport (= 4.2.6) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (11.2.2) + rdoc (4.2.2) + json (~> 1.4) + rest-client (2.0.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) + rmagick (2.15.4) + sass (3.4.22) + sass-rails (5.0.6) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + sdoc (0.4.1) + json (~> 1.7, >= 1.7.7) + rdoc (~> 4.0) + spring (1.7.2) + sprockets (3.7.0) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.1.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + stripe (1.48.0) + rest-client (>= 1.4, < 3.0) + thor (0.19.1) + thread_safe (0.3.5) + tilt (2.0.5) + turbolinks (5.0.0) + turbolinks-source (~> 5) + turbolinks-source (5.0.0) + tzinfo (1.2.2) + thread_safe (~> 0.1) + uglifier (3.0.0) + execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.2) + web-console (2.3.0) + activemodel (>= 4.0) + binding_of_caller (>= 0.7.2) + railties (>= 4.0) + sprockets-rails (>= 2.0, < 4.0) + +PLATFORMS + ruby + +DEPENDENCIES + bcrypt (~> 3.1.7) + bootstrap-sass (~> 3.3.6) + byebug + carrierwave + dotenv-rails + faker + font-awesome-rails + jbuilder (~> 2.0) + jquery-rails + money-rails + newrelic_rpm + pg + puma + quiet_assets + rails (= 4.2.6) + rails_12factor + rmagick + sass-rails (~> 5.0) + sdoc (~> 0.4.0) + spring + stripe + turbolinks + uglifier (>= 1.3.0) + web-console (~> 2.0) + +BUNDLED WITH + 1.11.2 diff --git a/README.md b/README.md new file mode 100644 index 0000000000..4264f2e93b --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Jungle + +A mini e-commerce application built with Rails 4.2 for purposes of teaching Rails by example. + + +## Setup + +1. Fork & Clone +2. Run `bundle install` to install dependencies +3. Create `config/database.yml` by copying `config/database.example.yml` +4. Update the username and password within the `development` section according to your local postgres credentials. +5. Run `bin/rake db:reset` to create, load and seed db +6. Create .env file based on .env.example +7. Sign up for a Stripe account +8. Put Stripe (test) keys into appropriate .env vars +9. Run `bin/rails s -b 0.0.0.0` to start the server + +## Stripe Testing + +Use Credit Card # 4111 1111 1111 1111 for testing success scenarios. + +More information in their docs: + +## Dependencies + +* Rails 4.2 +* PostgreSQL 9.x +* Stripe + diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..ba6b733dd2 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js new file mode 100644 index 0000000000..3b46ebdc9b --- /dev/null +++ b/app/assets/javascripts/admin.js @@ -0,0 +1,5 @@ +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require bootstrap-sprockets +//= require_tree ./admin diff --git a/app/assets/javascripts/admin/.keep b/app/assets/javascripts/admin/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000000..7465856729 --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,17 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require bootstrap-sprockets +//= require_tree . diff --git a/app/assets/stylesheets/admin/.keep b/app/assets/stylesheets/admin/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss new file mode 100644 index 0000000000..bcc1ee3064 --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,12 @@ +// Vendor +@import "bootstrap-sprockets"; +@import "bootstrap"; +@import "font-awesome"; + +// App +@import "products"; + +// Global +body { + padding-top: 70px; +} diff --git a/app/assets/stylesheets/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 0000000000..106bbbdd45 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,76 @@ +main section.products-index, +main section.categories-show { + + .products { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: space-around; + + .product { + // flex: 1; + max-width: 260px; + // so that footer within can be positioned absolutely + position: relative; + + border: 1px solid #ccc; + border-radius: 5px; + padding: 15px; + padding-bottom: 80px; + margin-top: 20px; + // margin: 10px; + + header img { + max-width: 100%; + max-height: 140px; + margin: auto; + display: block; + } + + footer { + position: absolute; + bottom: 0; + left: 0; + background-color: #EEE; + padding: 15px; + border-bottom-left-radius: 5px; + border-bottom-right-radius: 5px; + width: 100%; + opacity: 0.3; + transition: all 0.3s; + } + + aside.price { + position: absolute; + top: 0; + right: 0; + padding: 10px; + background-color: #eee; + border-top-right-radius: 4px; + border-bottom-left-radius: 20px; + font-size: 0.8em; + } + + &:hover { + + border-color: #999; + + footer { + opacity: 1.0; + } + } + + } + } +} + +main section.products-show { + + .product-detail { + img.main-img { + max-width: 100%; + } + } +} + + diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb new file mode 100644 index 0000000000..b508a2a3cf --- /dev/null +++ b/app/controllers/admin/dashboard_controller.rb @@ -0,0 +1,4 @@ +class Admin::DashboardController < ApplicationController + def show + end +end diff --git a/app/controllers/admin/products_controller.rb b/app/controllers/admin/products_controller.rb new file mode 100644 index 0000000000..9551c2b680 --- /dev/null +++ b/app/controllers/admin/products_controller.rb @@ -0,0 +1,40 @@ +class Admin::ProductsController < ApplicationController + + def index + @products = Product.order(id: :desc).all + end + + def new + @product = Product.new + end + + def create + @product = Product.new(product_params) + + if @product.save + redirect_to [:admin, products], notice: 'Product created!' + else + render :new + end + end + + def destroy + @product = Product.find params[:id] + @product.destroy + redirect_to [:admin, :products], notice: 'Product deleted!' + end + + private + + def product_params + params.require(:product).permit( + :name, + :description, + :category_id, + :quantity, + :image, + :price + ) + end + +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000000..16d683106b --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,22 @@ +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 + + private + + def cart + # value = cookies[:cart] || JSON.generate({}) + @cart ||= cookies[:cart].present? ? JSON.parse(cookies[:cart]) : {} + end + helper_method :cart + + def update_cart(new_cart) + cookies[:cart] = { + value: JSON.generate(new_cart), + expires: 10.days.from_now + } + cookies[:cart] + end + +end diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb new file mode 100644 index 0000000000..9315358878 --- /dev/null +++ b/app/controllers/carts_controller.rb @@ -0,0 +1,29 @@ +class CartsController < ApplicationController + + def show + end + + def add_item + product_id = params[:product_id].to_s + + item = cart[product_id] || { "quantity" => 0 } + item["quantity"] += 1 + cart[product_id] = item + update_cart cart + + redirect_to :back + end + + def remove_item + product_id = params[:product_id].to_s + + item = cart[product_id] || { "quantity" => 1 } + item["quantity"] -= 1 + cart[product_id] = item + cart.delete(product_id) if item["quantity"] < 1 + update_cart cart + + redirect_to :back + end + +end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000000..8aa5407241 --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,8 @@ +class CategoriesController < ApplicationController + + def show + @category = Category.find(params[:id]) + @products = @category.products.order(created_at: :desc) + end + +end diff --git a/app/controllers/checkouts_controller.rb b/app/controllers/checkouts_controller.rb new file mode 100644 index 0000000000..21e55b22a2 --- /dev/null +++ b/app/controllers/checkouts_controller.rb @@ -0,0 +1,2 @@ +class CheckoutsController < ApplicationController +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..d9e4a4a90a --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,70 @@ +class OrdersController < ApplicationController + + def show + @order = Order.find(params[:id]) + end + + def create + charge = perform_stripe_charge + order = create_order(charge) + + if order.valid? + empty_cart! + redirect_to order, notice: 'Your Order has been placed.' + else + redirect_to cart_path, error: order.errors.full_messages.first + end + + rescue Stripe::CardError => e + redirect_to cart_path, error: e.message + end + + private + + def empty_cart! + # empty hash means no products in cart :) + update_cart({}) + end + + def perform_stripe_charge + Stripe::Charge.create( + source: params[:stripeToken], + amount: cart_total, # in cents + description: "Khurram Virani's Jungle Order", + currency: 'cad' + ) + end + + def create_order(stripe_charge) + order = Order.new( + email: params[:stripeEmail], + total_cents: cart_total, + stripe_charge_id: stripe_charge.id, # returned by stripe + ) + cart.each do |product_id, details| + if product = Product.find_by(id: product_id) + quantity = details['quantity'].to_i + order.line_items.new( + product: product, + quantity: quantity, + item_price: product.price, + total_price: product.price * quantity + ) + end + end + order.save! + order + end + + # returns total in cents not dollars (stripe uses cents as well) + def cart_total + total = 0 + cart.each do |product_id, details| + if p = Product.find_by(id: product_id) + total += p.price_cents * details['quantity'].to_i + end + end + total + end + +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 0000000000..1e82ef27ac --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,11 @@ +class ProductsController < ApplicationController + + def index + @products = Product.all.order(created_at: :desc) + end + + def show + @product = Product.find params[:id] + end + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000000..de6be7945c --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/mailers/.keep b/app/mailers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/models/.keep b/app/models/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..ccaab7c6a9 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,5 @@ +class Category < ActiveRecord::Base + + has_many :products + +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/models/line_item.rb b/app/models/line_item.rb new file mode 100644 index 0000000000..c032ed3956 --- /dev/null +++ b/app/models/line_item.rb @@ -0,0 +1,9 @@ +class LineItem < ActiveRecord::Base + + belongs_to :order + belongs_to :product + + monetize :item_price_cents, numericality: true + monetize :total_price_cents, numericality: true + +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..a32e86156b --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,10 @@ +class Order < ActiveRecord::Base + + belongs_to :user + has_many :line_items + + monetize :total_cents, numericality: true + + validates :stripe_charge_id, presence: true + +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 0000000000..25d97c195d --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,13 @@ +class Product < ActiveRecord::Base + + monetize :price_cents, numericality: true + mount_uploader :image, ProductImageUploader + + belongs_to :category + + validates :name, presence: true + validates :price, presence: true + validates :quantity, presence: true + validates :category, presence: true + +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..369e3519a9 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,9 @@ +class User < ActiveRecord::Base + + has_secure_password + + validates :first_name, presence: true + validates :last_name, presence: true + validates :email, presence: true, uniqueness: { case_sensitive: false } + +end diff --git a/app/uploaders/product_image_uploader.rb b/app/uploaders/product_image_uploader.rb new file mode 100644 index 0000000000..9519ba3c7a --- /dev/null +++ b/app/uploaders/product_image_uploader.rb @@ -0,0 +1,55 @@ +# encoding: utf-8 + +class ProductImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + include CarrierWave::RMagick + # include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + storage :file + # storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + version :tiny do + process resize_to_fit: [100, 100] + end + + version :thumb do + process resize_to_fit: [300, 300] + end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + def extension_white_list + %w(jpg jpeg png) + end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/admin/dashboard/show.html.erb b/app/views/admin/dashboard/show.html.erb new file mode 100644 index 0000000000..bf5a3f629b --- /dev/null +++ b/app/views/admin/dashboard/show.html.erb @@ -0,0 +1,2 @@ +

Admin::Dashboard#show

+

Find me in app/views/admin/dashboard/show.html.erb

diff --git a/app/views/admin/products/_product.html.erb b/app/views/admin/products/_product.html.erb new file mode 100644 index 0000000000..9b31a456b6 --- /dev/null +++ b/app/views/admin/products/_product.html.erb @@ -0,0 +1,22 @@ + + + <%= image_tag product.image.tiny %> + + +

<%= product.name %>

+
+

<%= product.description %>

+ + + <%= product.category.name %> + + + <%= product.price %> + + + <%= product.quantity %> + + + <%= link_to fa_icon('trash'), [:admin, product], class: 'btn btn-sm btn-danger', method: :delete, data: { confirm: "Are you sure?" } %> + + \ No newline at end of file diff --git a/app/views/admin/products/index.html.erb b/app/views/admin/products/index.html.erb new file mode 100644 index 0000000000..a8da52adac --- /dev/null +++ b/app/views/admin/products/index.html.erb @@ -0,0 +1,30 @@ +
+ + + +
+ <%= link_to '+ New Product', [:new, :admin, :product], class: 'btn btn-info' %> +
+ +
+ + + + + + + + + + + + + <%= render @products %> + +
ProductCategoryPriceQty Remaining
+ +
+ +
diff --git a/app/views/admin/products/new.html.erb b/app/views/admin/products/new.html.erb new file mode 100644 index 0000000000..aa33513ca9 --- /dev/null +++ b/app/views/admin/products/new.html.erb @@ -0,0 +1,63 @@ +
+ + + +
+ <%= link_to 'All Products', [:admin, :products], class: 'btn btn-info' %> +
+ +
+
+ <%= form_for [:admin, @product] do |form| %> + + <% if form.object.errors.any? %> +
+ The following errors prevented saving: +
    + <% form.object.errors.full_messages.each do |error| %> +
  • <%= error %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :name %> + <%= form.text_field :name, class: 'form-control' %> +
+ +
+ <%= form.label :description %> + <%= form.text_area :description, class: 'form-control' %> +
+ +
+ <%= form.label :category %> + <%= form.select :category, options_from_collection_for_select(Category.all.order(:name), :id, :name), { include_blank: true }, class: 'form-control' %> +
+ +
+ <%= form.label :quantity %> + <%= form.number_field :quantity, class: 'form-control' %> +
+ +
+ <%= form.label :price %> + <%= form.text_field :price, class: 'form-control' %> +
+ + + +
+ <%= form.label :image %> + <%= form.file_field :image %> +
+ + <%= form.submit 'Create Product', class: 'btn btn-primary' %> + <% end %> +
+
+ +
diff --git a/app/views/carts/_item.html.erb b/app/views/carts/_item.html.erb new file mode 100644 index 0000000000..df2bf2e13b --- /dev/null +++ b/app/views/carts/_item.html.erb @@ -0,0 +1,32 @@ +<% quantity = details['quantity'].to_i %> + +<% if product = Product.find_by(id: product_id) %> + <% item_total = product.price * quantity %> + <% @cart_total += item_total %> + + + + <%= image_tag product.image.tiny %> + + +

<%= product.name %>

+
+

<%= product.description %>

+ + + <%= product.price %> + + + <%= link_to remove_item_cart_path(product_id: product_id), class: 'btn btn-xs btn-danger', method: :delete do %> + - + <% end %> + <%= quantity %> + <%= link_to add_item_cart_path(product_id: product_id), class: 'btn btn-xs btn-success', method: :put do %> + + + <% end %> + + + <%= item_total %> + + +<% end %> diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb new file mode 100644 index 0000000000..91951df76d --- /dev/null +++ b/app/views/carts/show.html.erb @@ -0,0 +1,53 @@ +
+ + + +
+ + + + + + + + + + + <% @cart_total = 0 %> + <% cart.each do |product_id, details| %> + <%= render 'item', product_id: product_id, details: details %> + <% end %> + + + + + + + +
ProductUnit PriceQuantityPrice
+ TOTAL: + + <%= @cart_total %> +
+
+ +
+
+ <%= form_tag orders_path do %> + + <% end %> +
+
+ +
diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb new file mode 100644 index 0000000000..97f232edf4 --- /dev/null +++ b/app/views/categories/show.html.erb @@ -0,0 +1,14 @@ +
+ + + +
+ <%= render @products %> +
+ +
diff --git a/app/views/layouts/_top_nav.html.erb b/app/views/layouts/_top_nav.html.erb new file mode 100644 index 0000000000..57c3159d49 --- /dev/null +++ b/app/views/layouts/_top_nav.html.erb @@ -0,0 +1,49 @@ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..b59d7a3047 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,19 @@ + + + + Jungle + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + + <%= render 'layouts/top_nav' %> + +
+ <%= yield %> +
+ + <%= yield :end_of_body %> + + diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb new file mode 100644 index 0000000000..63658e6ac6 --- /dev/null +++ b/app/views/orders/show.html.erb @@ -0,0 +1,13 @@ +
+ + + +
+

Thank you for your order!

+
+ + <%= link_to "Continue Shopping", root_path, class: 'btn btn-lg btn-primary' %> + +
diff --git a/app/views/products/_product.html.erb b/app/views/products/_product.html.erb new file mode 100644 index 0000000000..7bcef07dde --- /dev/null +++ b/app/views/products/_product.html.erb @@ -0,0 +1,23 @@ +
+
+ <%= link_to product do %> + <%= image_tag product.image.thumb, alt: product.name %> +

<%= product.name %>

+ <% end %> +
+

+ <%= product.description %> +

+
+ <%= link_to add_item_cart_path(product_id: product.id), class: 'btn btn-primary', method: :put do %> + <%= fa_icon "shopping-cart", text: 'Add' %> + <% end %> + <%= link_to product, class: 'btn btn-default pull-right' do %> + Details » + <% end %> +
+ + +
diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 0000000000..0db06dbc25 --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,11 @@ +
+ + + +
+ <%= render @products %> +
+ +
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb new file mode 100644 index 0000000000..64d02317dd --- /dev/null +++ b/app/views/products/show.html.erb @@ -0,0 +1,31 @@ +
+ + + +
+ +
+ +
+ <%= image_tag @product.image.url, class: 'main-img' %> +
+ +
+
+
Name
+
<%= @product.name %>
+
Description
+
<%= @product.description %>
+
Quantity
+
<%= @product.quantity %>
+
Price
+
<%= @product.price %>
+
+
+
+ +
+ +
diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000000..66e9889e8b --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000000..5191e6927a --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000000..17240489f6 --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000000..acdb2c1389 --- /dev/null +++ b/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000000..bd83b25412 --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000000..8505cda979 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,41 @@ +require File.expand_path('../boot', __FILE__) + +require "rails" +# Pick the frameworks you want: +require "active_model/railtie" +require "active_job/railtie" +require "active_record/railtie" +require "action_controller/railtie" +require "action_mailer/railtie" +require "action_view/railtie" +require "sprockets/railtie" +# require "rails/test_unit/railtie" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Jungle + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + + config.generators do |g| + g.skip_routes true + g.helper false + g.assets false + end + + # Do not swallow errors in after_commit/after_rollback callbacks. + config.active_record.raise_in_transactional_callbacks = true + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000000..6b750f00b1 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/database.example.yml b/config/database.example.yml new file mode 100644 index 0000000000..ccc86e576b --- /dev/null +++ b/config/database.example.yml @@ -0,0 +1,85 @@ +# PostgreSQL. Versions 8.2 and up are supported. +# +# Install the pg driver: +# gem install pg +# On OS X with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On OS X with MacPorts: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see rails configuration guide + # http://guides.rubyonrails.org/configuring.html#database-pooling + pool: 5 + +development: + <<: *default + database: jungle_development + username: development + password: development + + # The specified database role being used to connect to postgres. + # To create additional roles in postgres see `$ createuser --help`. + # When left blank, postgres will use the default role. This is + # the same name as the operating system user that initialized the database. + #username: jungle + + # The password associated with the postgres role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: jungle_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + url: <%= ENV['DATABASE_URL'] %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000000..ee8d90dc65 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000000..b55e2144b6 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,41 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000000..5c1b32e486 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,79 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like + # NGINX, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000000..1c19f08b28 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static file server for tests with Cache-Control for performance. + config.serve_static_files = true + config.static_cache_control = 'public, max-age=3600' + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Randomize the order test cases are executed. + config.active_support.test_order = :random + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000000..01ef3e6630 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000000..59385cdf37 --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000000..7f70458dee --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000..4a994e1e7b --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000000..ac033bf9dc --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000000..dc1899682b --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 0000000000..827e12fe82 --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_jungle_session' diff --git a/config/initializers/stripe.rb b/config/initializers/stripe.rb new file mode 100644 index 0000000000..7e4a7875f1 --- /dev/null +++ b/config/initializers/stripe.rb @@ -0,0 +1,6 @@ +Rails.configuration.stripe = { + :publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'], + :secret_key => ENV['STRIPE_SECRET_KEY'] +} + +Stripe.api_key = Rails.configuration.stripe[:secret_key] diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000000..33725e95fd --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000000..0653957166 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000000..1ed72b497f --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,74 @@ +Rails.application.routes.draw do + + root to: 'products#index' + + resources :products, only: [:index, :show] + resources :categories, only: [:show] + + resource :cart, only: [:show] do + put :add_item + delete :remove_item + end + + resources :orders, only: [:create, :show] + + namespace :admin do + root to: 'dashboard#show' + resources :products, except: [:edit, :update, :show] + end + + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end +end diff --git a/db/migrate/20160621152728_create_products.rb b/db/migrate/20160621152728_create_products.rb new file mode 100644 index 0000000000..b40272925f --- /dev/null +++ b/db/migrate/20160621152728_create_products.rb @@ -0,0 +1,13 @@ +class CreateProducts < ActiveRecord::Migration + def change + create_table :products do |t| + t.string :name + t.text :description + t.string :image + t.integer :price_cents + t.integer :quantity + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160621153741_create_categories.rb b/db/migrate/20160621153741_create_categories.rb new file mode 100644 index 0000000000..b574669a21 --- /dev/null +++ b/db/migrate/20160621153741_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration + def change + create_table :categories do |t| + t.string :name + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160621153855_add_category_id_to_products.rb b/db/migrate/20160621153855_add_category_id_to_products.rb new file mode 100644 index 0000000000..86eefda2e3 --- /dev/null +++ b/db/migrate/20160621153855_add_category_id_to_products.rb @@ -0,0 +1,5 @@ +class AddCategoryIdToProducts < ActiveRecord::Migration + def change + add_reference :products, :category, index: true, foreign_key: true + end +end diff --git a/db/migrate/20160622113553_create_orders.rb b/db/migrate/20160622113553_create_orders.rb new file mode 100644 index 0000000000..706b2bfc41 --- /dev/null +++ b/db/migrate/20160622113553_create_orders.rb @@ -0,0 +1,8 @@ +class CreateOrders < ActiveRecord::Migration + def change + create_table :orders do |t| + t.integer :total_cents + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160623110200_add_stripe_charge_id_to_orders.rb b/db/migrate/20160623110200_add_stripe_charge_id_to_orders.rb new file mode 100644 index 0000000000..b19f941482 --- /dev/null +++ b/db/migrate/20160623110200_add_stripe_charge_id_to_orders.rb @@ -0,0 +1,5 @@ +class AddStripeChargeIdToOrders < ActiveRecord::Migration + def change + add_column :orders, :stripe_charge_id, :string + end +end diff --git a/db/migrate/20160623222000_create_line_items.rb b/db/migrate/20160623222000_create_line_items.rb new file mode 100644 index 0000000000..97ae743371 --- /dev/null +++ b/db/migrate/20160623222000_create_line_items.rb @@ -0,0 +1,13 @@ +class CreateLineItems < ActiveRecord::Migration + def change + create_table :line_items do |t| + t.references :order, index: true, foreign_key: true + t.references :product, index: true, foreign_key: true + t.integer :quantity + t.integer :item_price_cents + t.integer :total_price_cents + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160625062916_add_email_to_orders.rb b/db/migrate/20160625062916_add_email_to_orders.rb new file mode 100644 index 0000000000..7f9c77d81a --- /dev/null +++ b/db/migrate/20160625062916_add_email_to_orders.rb @@ -0,0 +1,5 @@ +class AddEmailToOrders < ActiveRecord::Migration + def change + add_column :orders, :email, :string + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..cc484a2f0a --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,62 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20160625062916) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "line_items", force: :cascade do |t| + t.integer "order_id" + t.integer "product_id" + t.integer "quantity" + t.integer "item_price_cents" + t.integer "total_price_cents" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "line_items", ["order_id"], name: "index_line_items_on_order_id", using: :btree + add_index "line_items", ["product_id"], name: "index_line_items_on_product_id", using: :btree + + create_table "orders", force: :cascade do |t| + t.integer "total_cents" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "stripe_charge_id" + t.string "email" + end + + create_table "products", force: :cascade do |t| + t.string "name" + t.text "description" + t.string "image" + t.integer "price_cents" + t.integer "quantity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "category_id" + end + + add_index "products", ["category_id"], name: "index_products_on_category_id", using: :btree + + add_foreign_key "line_items", "orders" + add_foreign_key "line_items", "products" + add_foreign_key "products", "categories" +end diff --git a/db/seed_assets/apparel1.jpg b/db/seed_assets/apparel1.jpg new file mode 100644 index 0000000000..148ffbd48e Binary files /dev/null and b/db/seed_assets/apparel1.jpg differ diff --git a/db/seed_assets/apparel2.jpg b/db/seed_assets/apparel2.jpg new file mode 100644 index 0000000000..089c47c83a Binary files /dev/null and b/db/seed_assets/apparel2.jpg differ diff --git a/db/seed_assets/apparel3.jpg b/db/seed_assets/apparel3.jpg new file mode 100644 index 0000000000..f1976de30b Binary files /dev/null and b/db/seed_assets/apparel3.jpg differ diff --git a/db/seed_assets/apparel4.jpg b/db/seed_assets/apparel4.jpg new file mode 100644 index 0000000000..9f62c9d0d4 Binary files /dev/null and b/db/seed_assets/apparel4.jpg differ diff --git a/db/seed_assets/apparel5.jpg b/db/seed_assets/apparel5.jpg new file mode 100644 index 0000000000..cac937d64f Binary files /dev/null and b/db/seed_assets/apparel5.jpg differ diff --git a/db/seed_assets/apparel6.jpg b/db/seed_assets/apparel6.jpg new file mode 100644 index 0000000000..a014633b71 Binary files /dev/null and b/db/seed_assets/apparel6.jpg differ diff --git a/db/seed_assets/electronics1.jpg b/db/seed_assets/electronics1.jpg new file mode 100644 index 0000000000..073215f5b3 Binary files /dev/null and b/db/seed_assets/electronics1.jpg differ diff --git a/db/seed_assets/electronics2.jpg b/db/seed_assets/electronics2.jpg new file mode 100644 index 0000000000..aad592ea31 Binary files /dev/null and b/db/seed_assets/electronics2.jpg differ diff --git a/db/seed_assets/electronics3.jpg b/db/seed_assets/electronics3.jpg new file mode 100644 index 0000000000..e0d630717e Binary files /dev/null and b/db/seed_assets/electronics3.jpg differ diff --git a/db/seed_assets/furniture1.jpg b/db/seed_assets/furniture1.jpg new file mode 100644 index 0000000000..f3bd38fd78 Binary files /dev/null and b/db/seed_assets/furniture1.jpg differ diff --git a/db/seed_assets/furniture2.jpg b/db/seed_assets/furniture2.jpg new file mode 100644 index 0000000000..7337510871 Binary files /dev/null and b/db/seed_assets/furniture2.jpg differ diff --git a/db/seed_assets/furniture3.jpg b/db/seed_assets/furniture3.jpg new file mode 100644 index 0000000000..475ba08b48 Binary files /dev/null and b/db/seed_assets/furniture3.jpg differ diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..de3384d0bd --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,133 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) + +puts "Seeding Data ..." + +# Helper functions +def open_asset(file_name) + File.open(Rails.root.join('db', 'seed_assets', file_name)) +end + +# Only run on development (local) instances not on production, etc. +raise "Development seeds only (for now)!" unless Rails.env.development? + +# Let's do this ... + +## CATEGORIES + +puts "Finding or Creating Categories ..." + +cat1 = Category.find_or_create_by! name: 'Apparel' +cat2 = Category.find_or_create_by! name: 'Electronics' +cat3 = Category.find_or_create_by! name: 'Furniture' + +## PRODUCTS + +puts "Re-creating Products ..." + +Product.destroy_all + +cat1.products.create!({ + name: 'Men\'s Classy shirt', + description: Faker::Hipster.paragraph(4), + image: open_asset('apparel1.jpg'), + quantity: 10, + price: 64.99 +}) + +cat1.products.create!({ + name: 'Women\'s Zebra pants', + description: Faker::Hipster.paragraph(4), + image: open_asset('apparel2.jpg'), + quantity: 18, + price: 124.99 +}) + +cat1.products.create!({ + name: 'Hipster Hat', + description: Faker::Hipster.paragraph(4), + image: open_asset('apparel3.jpg'), + quantity: 4, + price: 34.49 +}) + +cat1.products.create!({ + name: 'Hipster Socks', + description: Faker::Hipster.paragraph(4), + image: open_asset('apparel4.jpg'), + quantity: 8, + price: 25.00 +}) + +cat1.products.create!({ + name: 'Russian Spy Shoes', + description: Faker::Hipster.paragraph(4), + image: open_asset('apparel5.jpg'), + quantity: 8, + price: 1_225.00 +}) + +cat1.products.create!({ + name: 'Human Feet Shoes', + description: Faker::Hipster.paragraph(4), + image: open_asset('apparel6.jpg'), + quantity: 82, + price: 224.50 +}) + + +cat2.products.create!({ + name: 'Modern Skateboards', + description: Faker::Hipster.paragraph(4), + image: open_asset('electronics1.jpg'), + quantity: 40, + price: 164.49 +}) + +cat2.products.create!({ + name: 'Hotdog Slicer', + description: Faker::Hipster.paragraph(4), + image: open_asset('electronics2.jpg'), + quantity: 3, + price: 26.00 +}) + +cat2.products.create!({ + name: 'World\'s Largest Smartwatch', + description: Faker::Hipster.paragraph(4), + image: open_asset('electronics3.jpg'), + quantity: 32, + price: 2_026.29 +}) + +cat3.products.create!({ + name: 'Optimal Sleeping Bed', + description: Faker::Hipster.paragraph(4), + image: open_asset('furniture1.jpg'), + quantity: 320, + price: 3_052.00 +}) + +cat3.products.create!({ + name: 'Electric Chair', + description: Faker::Hipster.paragraph(4), + image: open_asset('furniture2.jpg'), + quantity: 2, + price: 987.65 +}) + +cat3.products.create!({ + name: 'Red Bookshelf', + description: Faker::Hipster.paragraph(4), + image: open_asset('furniture3.jpg'), + quantity: 23, + price: 2_483.75 +}) + + +puts "DONE!" diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000000..b612547fc2 --- /dev/null +++ b/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/422.html b/public/422.html new file mode 100644 index 0000000000..a21f82b3bd --- /dev/null +++ b/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000000..061abc587d --- /dev/null +++ b/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000000..3c9c7c01f3 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep new file mode 100644 index 0000000000..e69de29bb2