From f4164dc00b8d3baec963a7418eaffff33fafb93e Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Wed, 17 Oct 2018 11:23:08 -0700 Subject: [PATCH 001/281] initial rails setup --- .gitignore | 27 ++ .ruby-version | 1 + Gemfile | 81 +++++ Gemfile.lock | 277 ++++++++++++++++++ Guardfile | 9 + Rakefile | 6 + app/assets/config/manifest.js | 3 + app/assets/images/.keep | 0 app/assets/javascripts/application.js | 20 ++ app/assets/javascripts/cable.js | 13 + app/assets/javascripts/channels/.keep | 0 app/assets/stylesheets/application.scss | 18 ++ app/channels/application_cable/channel.rb | 4 + app/channels/application_cable/connection.rb | 4 + app/controllers/application_controller.rb | 2 + app/controllers/concerns/.keep | 0 app/helpers/application_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 3 + app/models/concerns/.keep | 0 app/views/layouts/application.html.erb | 15 + app/views/layouts/mailer.html.erb | 13 + app/views/layouts/mailer.text.erb | 1 + bin/bundle | 3 + bin/rails | 9 + bin/rake | 9 + bin/setup | 36 +++ bin/spring | 17 ++ bin/update | 31 ++ bin/yarn | 11 + config.ru | 5 + config/application.rb | 25 ++ config/boot.rb | 4 + config/cable.yml | 10 + config/credentials.yml.enc | 1 + config/database.yml | 85 ++++++ config/environment.rb | 5 + config/environments/development.rb | 61 ++++ config/environments/production.rb | 94 ++++++ config/environments/test.rb | 46 +++ .../application_controller_renderer.rb | 8 + config/initializers/assets.rb | 14 + config/initializers/backtrace_silencers.rb | 7 + .../initializers/content_security_policy.rb | 25 ++ config/initializers/cookies_serializer.rb | 5 + .../initializers/filter_parameter_logging.rb | 4 + config/initializers/inflections.rb | 16 + config/initializers/mime_types.rb | 4 + config/initializers/wrap_parameters.rb | 14 + config/locales/en.yml | 33 +++ config/puma.rb | 34 +++ config/routes.rb | 3 + config/spring.rb | 6 + config/storage.yml | 34 +++ db/seeds.rb | 7 + lib/assets/.keep | 0 lib/tasks/.keep | 0 log/.keep | 0 package.json | 5 + public/404.html | 67 +++++ public/422.html | 67 +++++ public/500.html | 66 +++++ public/apple-touch-icon-precomposed.png | 0 public/apple-touch-icon.png | 0 public/favicon.ico | 0 public/robots.txt | 1 + storage/.keep | 0 test/application_system_test_case.rb | 5 + test/controllers/.keep | 0 test/fixtures/.keep | 0 test/fixtures/files/.keep | 0 test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/system/.keep | 0 test/test_helper.rb | 24 ++ tmp/.keep | 0 vendor/.keep | 0 80 files changed, 1406 insertions(+) create mode 100644 .gitignore create mode 100644 .ruby-version create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Guardfile create mode 100644 Rakefile create mode 100644 app/assets/config/manifest.js create mode 100644 app/assets/images/.keep create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/javascripts/cable.js create mode 100644 app/assets/javascripts/channels/.keep create mode 100644 app/assets/stylesheets/application.scss create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/helpers/application_helper.rb create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100755 bin/spring create mode 100755 bin/update create mode 100755 bin/yarn create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/cable.yml create mode 100644 config/credentials.yml.enc create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/backtrace_silencers.rb create mode 100644 config/initializers/content_security_policy.rb create mode 100644 config/initializers/cookies_serializer.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/initializers/mime_types.rb create mode 100644 config/initializers/wrap_parameters.rb create mode 100644 config/locales/en.yml create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/spring.rb create mode 100644 config/storage.yml create mode 100644 db/seeds.rb create mode 100644 lib/assets/.keep create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 package.json create mode 100644 public/404.html create mode 100644 public/422.html create mode 100644 public/500.html create mode 100644 public/apple-touch-icon-precomposed.png create mode 100644 public/apple-touch-icon.png create mode 100644 public/favicon.ico create mode 100644 public/robots.txt create mode 100644 storage/.keep create mode 100644 test/application_system_test_case.rb create mode 100644 test/controllers/.keep create mode 100644 test/fixtures/.keep create mode 100644 test/fixtures/files/.keep create mode 100644 test/helpers/.keep create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/system/.keep create mode 100644 test/test_helper.rb create mode 100644 tmp/.keep create mode 100644 vendor/.keep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..18b43c9cd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# 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 bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore uploaded files in development +/storage/* +!/storage/.keep + +/node_modules +/yarn-error.log + +/public/assets +.byebug_history + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000000..25c81fe399 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.5.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..6219256bd8 --- /dev/null +++ b/Gemfile @@ -0,0 +1,81 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.5.1' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.2.1' +# Use postgresql as the database for Active Record +gem 'pg', '>= 0.18', '< 2.0' +# Use Puma as the app server +gem 'puma', '~> 3.11' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'mini_racer', platforms: :ruby + +# Use CoffeeScript for .coffee assets and views +# gem 'coffee-rails', '~> 4.2' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.5' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use ActiveStorage variant +# gem 'mini_magick', '~> 4.8' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.1.0', require: false + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +end + +group :development do + # Access an interactive console on exception pages or by calling 'console' anywhere in the code. + gem 'web-console', '>= 3.3.0' + gem 'listen', '>= 3.0.5', '< 3.2' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' +end + +group :test do + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '>= 2.15' + gem 'selenium-webdriver' + # Easy installation and use of chromedriver to run system tests with Chrome + gem 'chromedriver-helper' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'jquery-rails' +gem 'jquery-turbolinks' +gem 'bootstrap', '~> 4.1.3' +group :development, :test do + gem 'pry-rails' +end + +group :development do + gem 'better_errors' + gem 'binding_of_caller' + gem 'guard' + gem 'guard-minitest' +end + +group :test do + gem 'minitest-rails' + gem 'minitest-reporters' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..51100b2a1d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,277 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.2.1) + actionpack (= 5.2.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.1) + actionpack (= 5.2.1) + actionview (= 5.2.1) + activejob (= 5.2.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.2.1) + actionview (= 5.2.1) + activesupport (= 5.2.1) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.1) + activesupport (= 5.2.1) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.1) + activesupport (= 5.2.1) + globalid (>= 0.3.6) + activemodel (5.2.1) + activesupport (= 5.2.1) + activerecord (5.2.1) + activemodel (= 5.2.1) + activesupport (= 5.2.1) + arel (>= 9.0) + activestorage (5.2.1) + actionpack (= 5.2.1) + activerecord (= 5.2.1) + marcel (~> 0.3.1) + activesupport (5.2.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + ansi (1.5.0) + archive-zip (0.11.0) + io-like (~> 0.3.0) + arel (9.0.0) + autoprefixer-rails (9.2.1) + execjs + better_errors (2.5.0) + coderay (>= 1.0.0) + erubi (>= 1.0.0) + rack (>= 0.9.0) + bindex (0.5.0) + binding_of_caller (0.8.0) + debug_inspector (>= 0.0.1) + bootsnap (1.3.2) + msgpack (~> 1.0) + bootstrap (4.1.3) + autoprefixer-rails (>= 6.0.3) + popper_js (>= 1.12.9, < 2) + sass (>= 3.5.2) + builder (3.2.3) + byebug (10.0.2) + capybara (3.9.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + xpath (~> 3.1) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) + chromedriver-helper (2.1.0) + archive-zip (~> 0.10) + nokogiri (~> 1.8) + coderay (1.1.2) + concurrent-ruby (1.0.5) + crass (1.0.4) + debug_inspector (0.0.3) + erubi (1.7.1) + execjs (2.7.0) + ffi (1.9.25) + formatador (0.2.5) + globalid (0.4.1) + activesupport (>= 4.2.0) + guard (2.14.2) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (>= 1.0.12, < 2.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-minitest (2.4.6) + guard-compat (~> 1.2) + minitest (>= 3.0) + i18n (1.1.1) + concurrent-ruby (~> 1.0) + io-like (0.3.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.3) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-turbolinks (2.1.0) + railties (>= 3.1.0) + turbolinks + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) + loofah (2.2.2) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + lumberjack (1.0.13) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (0.9.0) + mimemagic (0.3.2) + mini_mime (1.0.1) + mini_portile2 (2.3.0) + minitest (5.11.3) + minitest-rails (3.0.0) + minitest (~> 5.8) + railties (~> 5.0) + minitest-reporters (1.3.5) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + msgpack (1.2.4) + multi_json (1.13.1) + nenv (0.3.0) + nio4r (2.3.1) + nokogiri (1.8.5) + mini_portile2 (~> 2.3.0) + notiffany (0.1.1) + nenv (~> 0.1) + shellany (~> 0.0) + pg (1.1.3) + popper_js (1.14.3) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.6) + pry (>= 0.10.4) + public_suffix (3.0.3) + puma (3.12.0) + rack (2.0.5) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.1) + actioncable (= 5.2.1) + actionmailer (= 5.2.1) + actionpack (= 5.2.1) + actionview (= 5.2.1) + activejob (= 5.2.1) + activemodel (= 5.2.1) + activerecord (= 5.2.1) + activestorage (= 5.2.1) + activesupport (= 5.2.1) + bundler (>= 1.3.0) + railties (= 5.2.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) + railties (5.2.1) + actionpack (= 5.2.1) + activesupport (= 5.2.1) + method_source + rake (>= 0.8.7) + thor (>= 0.19.0, < 2.0) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + ruby-progressbar (1.10.0) + ruby_dep (1.5.0) + rubyzip (1.2.2) + sass (3.6.0) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + selenium-webdriver (3.14.1) + childprocess (~> 0.5) + rubyzip (~> 1.2, >= 1.2.2) + shellany (0.0.1) + spring (2.0.2) + activesupport (>= 4.2) + spring-watcher-listen (2.0.1) + listen (>= 2.7, < 4.0) + spring (>= 1.2, < 3.0) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + turbolinks (5.2.0) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uglifier (4.1.19) + execjs (>= 0.3.0, < 3) + web-console (3.7.0) + actionview (>= 5.0) + activemodel (>= 5.0) + bindex (>= 0.4.0) + railties (>= 5.0) + websocket-driver (0.7.0) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + xpath (3.2.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + better_errors + binding_of_caller + bootsnap (>= 1.1.0) + bootstrap (~> 4.1.3) + byebug + capybara (>= 2.15) + chromedriver-helper + guard + guard-minitest + jbuilder (~> 2.5) + jquery-rails + jquery-turbolinks + listen (>= 3.0.5, < 3.2) + minitest-rails + minitest-reporters + pg (>= 0.18, < 2.0) + pry-rails + puma (~> 3.11) + rails (~> 5.2.1) + sass-rails (~> 5.0) + selenium-webdriver + spring + spring-watcher-listen (~> 2.0.0) + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console (>= 3.3.0) + +RUBY VERSION + ruby 2.5.1p57 + +BUNDLED WITH + 1.16.2 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000000..e34f706f4a --- /dev/null +++ b/Guardfile @@ -0,0 +1,9 @@ +guard :minitest, autorun: false, spring: true do + watch(%r{^app/(.+).rb$}) { |m| "test/#{m[1]}_test.rb" } + watch(%r{^app/controllers/application_controller.rb$}) { 'test/controllers' } + watch(%r{^app/controllers/(.+)_controller.rb$}) { |m| "test/integration/#{m[1]}_test.rb" } + watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } + watch(%r{^lib/(.+).rb$}) { |m| "test/lib/#{m[1]}_test.rb" } + watch(%r{^test/.+_test.rb$}) + watch(%r{^test/test_helper.rb$}) { 'test' } +end diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000000..e85f913914 --- /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_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000000..b16e53d6d5 --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css 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/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000000..4f73c21a7d --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,20 @@ +// 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, 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. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. + //= require jquery3 + //= require popper + //= require bootstrap-sprockets + +// +//= require rails-ujs +//= require activestorage +//= require turbolinks +//= require_tree . diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js new file mode 100644 index 0000000000..739aa5f022 --- /dev/null +++ b/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.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..8b1701e581 --- /dev/null +++ b/app/assets/stylesheets/application.scss @@ -0,0 +1,18 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + */ + +/* Custom bootstrap variables must be set or imported *before* bootstrap. */ +@import "bootstrap"; +/* Import scss content */ +@import "**/*"; diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000000..d672697283 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000000..0ff5442f47 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000000..09705d12ab --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 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/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000000..a009ace51c --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000000..286b2239d1 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000000..10a4cba84d --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..f18f1b6820 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,15 @@ + + + + Betsy + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000000..cbd34d2e9d --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000000..37f0bddbd7 --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000000..f19acf5b5c --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000000..5badb2fde0 --- /dev/null +++ b/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000000..d87d5f5781 --- /dev/null +++ b/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000000..94fd4d7977 --- /dev/null +++ b/bin/setup @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +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') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/spring b/bin/spring new file mode 100755 index 0000000000..fb2ec2ebb4 --- /dev/null +++ b/bin/spring @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + spring = lockfile.specs.detect { |spec| spec.name == "spring" } + if spring + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/bin/update b/bin/update new file mode 100755 index 0000000000..58bfaed518 --- /dev/null +++ b/bin/update @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 0000000000..460dd565b4 --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do + begin + exec "yarnpkg", *ARGV + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000000..f7ba0b527b --- /dev/null +++ b/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000000..5c09a3eefc --- /dev/null +++ b/config/application.rb @@ -0,0 +1,25 @@ +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Betsy + class Application < Rails::Application + config.generators do |g| + # Force new test files to be generated in the minitest-spec style + g.test_framework :minitest, spec: true + # Always use .js files, never .coffee + g.javascript_engine :js + end + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.2 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000000..b9e460cef3 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,4 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000000..dd2a324c68 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: betsy_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000000..f5c513e0a3 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +EZewcexkKXzfxCJnxJ42QJHtPtFIr6ttF3k/Dn2tBxMuhH+11uugdWZi45l18hSXqJEi6Xx5d8+kB1OlQbUf8+jetufAO6tZge5jQalqgZAqsgaL4YEvrKV/bSD/EOplqq//m9IIjPceD3BR7j43Vts8T90lyMpQohM9LowJ+dfAwYg3zpTodYisKLz1NwWYYC8X3Vuc3MV+WVQqRAYV9mfXE9X/+oomu9svAq0Zx66+GGMqXnfS+WbJA+z9yLZQyZ7vW+eRNOcdW92rQaSEqvTkx1O5akTYXWEdzAmE75QmbvrqUGBM3brOAsZMzlZy3VTLoeXJQBGhw3RGWORq/0Fp3p/CAX7WPUwCzmUp3X2bFzDgembJaopXobAFNgYpm2IET68pazL53U2eC2KYf8IQaV2mLGJ2G6rT--5Nz0OdRHNlc7y/Pw--H65G7tvuiWtt3wbZkM0Rzg== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000000..6903bb6083 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,85 @@ +# PostgreSQL. Versions 9.1 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: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + +development: + <<: *default + database: betsy_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: betsy + + # 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: betsy_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 + database: betsy_production + username: betsy + password: <%= ENV['BETSY_DATABASE_PASSWORD'] %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000000..426333bb46 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# 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..1311e3e4ef --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,61 @@ +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. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = 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 + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # 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 + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000000..5f6f3058c6 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,94 @@ +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 + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = 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 + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # 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 + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # 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 = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "betsy_#{Rails.env}" + + config.action_mailer.perform_caching = false + + # 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 + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # 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..0a38fd3ce9 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,46 @@ +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 public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # 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 + + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + + config.action_mailer.perform_caching = 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 + + # 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/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000000..89d2efab2b --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000000..4b828e80cb --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,14 @@ +# 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 +# Add Yarn node_modules folder to the asset load path. +Rails.application.config.assets.paths << Rails.root.join('node_modules') + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) 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/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 0000000000..d3bcaa5ec8 --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000000..5a6a32d371 --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +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/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000000..bbfc3961bf --- /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] +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..decc5a8573 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,33 @@ +# 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. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# 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/puma.rb b/config/puma.rb new file mode 100644 index 0000000000..a5eccf816b --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,34 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000000..787824f888 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html +end diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 0000000000..9fa7863f99 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w[ + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +].each { |path| Spring.watch(path) } diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 0000000000..d32f76e8fb --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000000..1beea2accd --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,7 @@ +# 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 rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) 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/package.json b/package.json new file mode 100644 index 0000000000..f874acf437 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "betsy", + "private": true, + "dependencies": {} +} diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000000..2be3af26fc --- /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..c08eac0d1d --- /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..78a030af22 --- /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/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 0000000000..e69de29bb2 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..37b576a4a0 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/storage/.keep b/storage/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000000..d19212abd5 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/system/.keep b/test/system/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000000..2b5172a7d6 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,24 @@ +ENV["RAILS_ENV"] = "test" +require File.expand_path("../../config/environment", __FILE__) +require "rails/test_help" +require "minitest/rails"require "minitest/reporters" # for Colorized output +# For colorful output! +Minitest::Reporters.use!( + Minitest::Reporters::SpecReporter.new, + ENV, + Minitest.backtrace_filter +) + + +# To add Capybara feature tests add `gem "minitest-rails-capybara"` +# to the test group in the Gemfile and uncomment the following: +# require "minitest/rails/capybara" + +# Uncomment for awesome colorful output +# require "minitest/pride" + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + # Add more helper methods to be used by all tests here... +end diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vendor/.keep b/vendor/.keep new file mode 100644 index 0000000000..e69de29bb2 From 8082a2542b6f763f04d2e8a0db62a745d511669d Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Thu, 18 Oct 2018 15:07:31 -0700 Subject: [PATCH 002/281] Adding tables and migrations --- app/models/item.rb | 2 + app/models/order.rb | 2 + app/models/orderitem.rb | 2 + app/models/review.rb | 2 + app/models/user.rb | 2 + db/migrate/20181018212109_create_users.rb | 14 +++ db/migrate/20181018212627_create_orders.rb | 18 ++++ .../20181018213025_create_orderitems.rb | 9 ++ db/migrate/20181018213306_create_items.rb | 15 ++++ db/migrate/20181018213354_create_reviews.rb | 10 +++ db/migrate/20181018214111_delete_uid.rb | 5 ++ db/migrate/20181018214131_add_uid_to_users.rb | 5 ++ ...181018214412_delete_provider_from_users.rb | 5 ++ .../20181018214431_add_provider_to_users.rb | 5 ++ ...81018214642_add_status_shipped_to_order.rb | 6 ++ .../20181018215031_delete_shipped_orders.rb | 5 ++ .../20181018215159_add_customer_to_order.rb | 5 ++ ...20181018215421_add_shipped_to_orderitem.rb | 5 ++ ...1018215601_add_order_and_item_orderitem.rb | 6 ++ db/migrate/20181018215915_add_user_to_item.rb | 5 ++ .../20181018220049_add_active_to_item.rb | 5 ++ ...1018220256_add_user_and_item_to_reviews.rb | 6 ++ db/schema.rb | 89 +++++++++++++++++++ test/fixtures/items.yml | 19 ++++ test/fixtures/orderitems.yml | 7 ++ test/fixtures/orders.yml | 25 ++++++ test/fixtures/reviews.yml | 9 ++ test/fixtures/users.yml | 17 ++++ test/models/item_test.rb | 9 ++ test/models/order_test.rb | 9 ++ test/models/orderitem_test.rb | 9 ++ test/models/review_test.rb | 9 ++ test/models/user_test.rb | 9 ++ 33 files changed, 350 insertions(+) create mode 100644 app/models/item.rb create mode 100644 app/models/order.rb create mode 100644 app/models/orderitem.rb create mode 100644 app/models/review.rb create mode 100644 app/models/user.rb create mode 100644 db/migrate/20181018212109_create_users.rb create mode 100644 db/migrate/20181018212627_create_orders.rb create mode 100644 db/migrate/20181018213025_create_orderitems.rb create mode 100644 db/migrate/20181018213306_create_items.rb create mode 100644 db/migrate/20181018213354_create_reviews.rb create mode 100644 db/migrate/20181018214111_delete_uid.rb create mode 100644 db/migrate/20181018214131_add_uid_to_users.rb create mode 100644 db/migrate/20181018214412_delete_provider_from_users.rb create mode 100644 db/migrate/20181018214431_add_provider_to_users.rb create mode 100644 db/migrate/20181018214642_add_status_shipped_to_order.rb create mode 100644 db/migrate/20181018215031_delete_shipped_orders.rb create mode 100644 db/migrate/20181018215159_add_customer_to_order.rb create mode 100644 db/migrate/20181018215421_add_shipped_to_orderitem.rb create mode 100644 db/migrate/20181018215601_add_order_and_item_orderitem.rb create mode 100644 db/migrate/20181018215915_add_user_to_item.rb create mode 100644 db/migrate/20181018220049_add_active_to_item.rb create mode 100644 db/migrate/20181018220256_add_user_and_item_to_reviews.rb create mode 100644 db/schema.rb create mode 100644 test/fixtures/items.yml create mode 100644 test/fixtures/orderitems.yml create mode 100644 test/fixtures/orders.yml create mode 100644 test/fixtures/reviews.yml create mode 100644 test/fixtures/users.yml create mode 100644 test/models/item_test.rb create mode 100644 test/models/order_test.rb create mode 100644 test/models/orderitem_test.rb create mode 100644 test/models/review_test.rb create mode 100644 test/models/user_test.rb diff --git a/app/models/item.rb b/app/models/item.rb new file mode 100644 index 0000000000..809e23f848 --- /dev/null +++ b/app/models/item.rb @@ -0,0 +1,2 @@ +class Item < ApplicationRecord +end diff --git a/app/models/order.rb b/app/models/order.rb new file mode 100644 index 0000000000..10281b3450 --- /dev/null +++ b/app/models/order.rb @@ -0,0 +1,2 @@ +class Order < ApplicationRecord +end diff --git a/app/models/orderitem.rb b/app/models/orderitem.rb new file mode 100644 index 0000000000..ebe5c835d9 --- /dev/null +++ b/app/models/orderitem.rb @@ -0,0 +1,2 @@ +class Orderitem < ApplicationRecord +end diff --git a/app/models/review.rb b/app/models/review.rb new file mode 100644 index 0000000000..b2ca4935ed --- /dev/null +++ b/app/models/review.rb @@ -0,0 +1,2 @@ +class Review < ApplicationRecord +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000000..379658a509 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,2 @@ +class User < ApplicationRecord +end diff --git a/db/migrate/20181018212109_create_users.rb b/db/migrate/20181018212109_create_users.rb new file mode 100644 index 0000000000..3a8f4217f1 --- /dev/null +++ b/db/migrate/20181018212109_create_users.rb @@ -0,0 +1,14 @@ +class CreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + t.integer :uid + t.string :name + t.string :nickname + t.string :email + t.string :image_url + t.string :provider + + t.timestamps + end + end +end diff --git a/db/migrate/20181018212627_create_orders.rb b/db/migrate/20181018212627_create_orders.rb new file mode 100644 index 0000000000..d273f0c0fa --- /dev/null +++ b/db/migrate/20181018212627_create_orders.rb @@ -0,0 +1,18 @@ +class CreateOrders < ActiveRecord::Migration[5.2] + def change + create_table :orders do |t| + t.string :name + t.string :email + t.string :mailing_address + t.string :name_on_card + t.integer :credit_card_num + t.integer :credit_card_exp_month + t.integer :credit_card_exp_year + t.integer :cvv_num + t.integer :zipcode + + + t.timestamps + end + end +end diff --git a/db/migrate/20181018213025_create_orderitems.rb b/db/migrate/20181018213025_create_orderitems.rb new file mode 100644 index 0000000000..7ee5d5e65a --- /dev/null +++ b/db/migrate/20181018213025_create_orderitems.rb @@ -0,0 +1,9 @@ +class CreateOrderitems < ActiveRecord::Migration[5.2] + def change + create_table :orderitems do |t| + t.integer :quantity_per_item + + t.timestamps + end + end +end diff --git a/db/migrate/20181018213306_create_items.rb b/db/migrate/20181018213306_create_items.rb new file mode 100644 index 0000000000..c729acf1c4 --- /dev/null +++ b/db/migrate/20181018213306_create_items.rb @@ -0,0 +1,15 @@ +class CreateItems < ActiveRecord::Migration[5.2] + def change + create_table :items do |t| + t.string :category + t.integer :price + t.string :image + t.integer :quantity_available + t.string :name + t.string :description + t.integer :avg_rating + + t.timestamps + end + end +end diff --git a/db/migrate/20181018213354_create_reviews.rb b/db/migrate/20181018213354_create_reviews.rb new file mode 100644 index 0000000000..4c50e6ab91 --- /dev/null +++ b/db/migrate/20181018213354_create_reviews.rb @@ -0,0 +1,10 @@ +class CreateReviews < ActiveRecord::Migration[5.2] + def change + create_table :reviews do |t| + t.string :description + t.integer :rating + + t.timestamps + end + end +end diff --git a/db/migrate/20181018214111_delete_uid.rb b/db/migrate/20181018214111_delete_uid.rb new file mode 100644 index 0000000000..d52b82ecf6 --- /dev/null +++ b/db/migrate/20181018214111_delete_uid.rb @@ -0,0 +1,5 @@ +class DeleteUid < ActiveRecord::Migration[5.2] + def change + remove_column :users, :uid + end +end diff --git a/db/migrate/20181018214131_add_uid_to_users.rb b/db/migrate/20181018214131_add_uid_to_users.rb new file mode 100644 index 0000000000..f36704e564 --- /dev/null +++ b/db/migrate/20181018214131_add_uid_to_users.rb @@ -0,0 +1,5 @@ +class AddUidToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :uid, :integer, null:false + end +end diff --git a/db/migrate/20181018214412_delete_provider_from_users.rb b/db/migrate/20181018214412_delete_provider_from_users.rb new file mode 100644 index 0000000000..875862d5de --- /dev/null +++ b/db/migrate/20181018214412_delete_provider_from_users.rb @@ -0,0 +1,5 @@ +class DeleteProviderFromUsers < ActiveRecord::Migration[5.2] + def change + remove_column :users, :provider + end +end diff --git a/db/migrate/20181018214431_add_provider_to_users.rb b/db/migrate/20181018214431_add_provider_to_users.rb new file mode 100644 index 0000000000..3f58d0f1a1 --- /dev/null +++ b/db/migrate/20181018214431_add_provider_to_users.rb @@ -0,0 +1,5 @@ +class AddProviderToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :provider, :string, null:false + end +end diff --git a/db/migrate/20181018214642_add_status_shipped_to_order.rb b/db/migrate/20181018214642_add_status_shipped_to_order.rb new file mode 100644 index 0000000000..22b11c61ff --- /dev/null +++ b/db/migrate/20181018214642_add_status_shipped_to_order.rb @@ -0,0 +1,6 @@ +class AddStatusShippedToOrder < ActiveRecord::Migration[5.2] + def change + add_column :orders, :status, :string, default: "pending" + add_column :orders, :shipped, :boolean, default: false + end +end diff --git a/db/migrate/20181018215031_delete_shipped_orders.rb b/db/migrate/20181018215031_delete_shipped_orders.rb new file mode 100644 index 0000000000..fc818b7024 --- /dev/null +++ b/db/migrate/20181018215031_delete_shipped_orders.rb @@ -0,0 +1,5 @@ +class DeleteShippedOrders < ActiveRecord::Migration[5.2] + def change + remove_column :orders, :shipped + end +end diff --git a/db/migrate/20181018215159_add_customer_to_order.rb b/db/migrate/20181018215159_add_customer_to_order.rb new file mode 100644 index 0000000000..833fdfe640 --- /dev/null +++ b/db/migrate/20181018215159_add_customer_to_order.rb @@ -0,0 +1,5 @@ +class AddCustomerToOrder < ActiveRecord::Migration[5.2] + def change + add_reference :orders, :user, foreign_key: true + end +end diff --git a/db/migrate/20181018215421_add_shipped_to_orderitem.rb b/db/migrate/20181018215421_add_shipped_to_orderitem.rb new file mode 100644 index 0000000000..0acb705f52 --- /dev/null +++ b/db/migrate/20181018215421_add_shipped_to_orderitem.rb @@ -0,0 +1,5 @@ +class AddShippedToOrderitem < ActiveRecord::Migration[5.2] + def change + add_column :orderitems, :shipped, :boolean, default:false + end +end diff --git a/db/migrate/20181018215601_add_order_and_item_orderitem.rb b/db/migrate/20181018215601_add_order_and_item_orderitem.rb new file mode 100644 index 0000000000..aba45c23b3 --- /dev/null +++ b/db/migrate/20181018215601_add_order_and_item_orderitem.rb @@ -0,0 +1,6 @@ +class AddOrderAndItemOrderitem < ActiveRecord::Migration[5.2] + def change + add_reference :orderitems, :order, foreign_key: true + add_reference :orderitems, :item, foreign_key: true + end +end diff --git a/db/migrate/20181018215915_add_user_to_item.rb b/db/migrate/20181018215915_add_user_to_item.rb new file mode 100644 index 0000000000..fb8251f1dd --- /dev/null +++ b/db/migrate/20181018215915_add_user_to_item.rb @@ -0,0 +1,5 @@ +class AddUserToItem < ActiveRecord::Migration[5.2] + def change + add_reference :items, :user, foreign_key: true + end +end diff --git a/db/migrate/20181018220049_add_active_to_item.rb b/db/migrate/20181018220049_add_active_to_item.rb new file mode 100644 index 0000000000..24f53330ee --- /dev/null +++ b/db/migrate/20181018220049_add_active_to_item.rb @@ -0,0 +1,5 @@ +class AddActiveToItem < ActiveRecord::Migration[5.2] + def change + add_column :items, :active, :boolean, default: true + end +end diff --git a/db/migrate/20181018220256_add_user_and_item_to_reviews.rb b/db/migrate/20181018220256_add_user_and_item_to_reviews.rb new file mode 100644 index 0000000000..e126811966 --- /dev/null +++ b/db/migrate/20181018220256_add_user_and_item_to_reviews.rb @@ -0,0 +1,6 @@ +class AddUserAndItemToReviews < ActiveRecord::Migration[5.2] + def change + add_reference :reviews, :user, foreign_key: true + add_reference :reviews, :item, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000000..58fd4e7265 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,89 @@ +# 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: 2018_10_18_220256) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "items", force: :cascade do |t| + t.string "category" + t.integer "price" + t.string "image" + t.integer "quantity_available" + t.string "name" + t.string "description" + t.integer "avg_rating" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id" + t.boolean "active", default: true + t.index ["user_id"], name: "index_items_on_user_id" + end + + create_table "orderitems", force: :cascade do |t| + t.integer "quantity_per_item" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "shipped", default: false + t.bigint "order_id" + t.bigint "item_id" + t.index ["item_id"], name: "index_orderitems_on_item_id" + t.index ["order_id"], name: "index_orderitems_on_order_id" + end + + create_table "orders", force: :cascade do |t| + t.string "name" + t.string "email" + t.string "mailing_address" + t.string "name_on_card" + t.integer "credit_card_num" + t.integer "credit_card_exp_month" + t.integer "credit_card_exp_year" + t.integer "cvv_num" + t.integer "zipcode" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "status", default: "pending" + t.bigint "user_id" + t.index ["user_id"], name: "index_orders_on_user_id" + end + + create_table "reviews", force: :cascade do |t| + t.string "description" + t.integer "rating" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id" + t.bigint "item_id" + t.index ["item_id"], name: "index_reviews_on_item_id" + t.index ["user_id"], name: "index_reviews_on_user_id" + end + + create_table "users", force: :cascade do |t| + t.string "name" + t.string "nickname" + t.string "email" + t.string "image_url" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "uid", null: false + t.string "provider", null: false + end + + add_foreign_key "items", "users" + add_foreign_key "orderitems", "items" + add_foreign_key "orderitems", "orders" + add_foreign_key "orders", "users" + add_foreign_key "reviews", "items" + add_foreign_key "reviews", "users" +end diff --git a/test/fixtures/items.yml b/test/fixtures/items.yml new file mode 100644 index 0000000000..2b02a520bb --- /dev/null +++ b/test/fixtures/items.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + category: MyString + price: 1 + image: MyString + quantity_available: 1 + name: MyString + description: MyString + avg_rating: 1 + +two: + category: MyString + price: 1 + image: MyString + quantity_available: 1 + name: MyString + description: MyString + avg_rating: 1 diff --git a/test/fixtures/orderitems.yml b/test/fixtures/orderitems.yml new file mode 100644 index 0000000000..fee675af78 --- /dev/null +++ b/test/fixtures/orderitems.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + quantity_per_item: 1 + +two: + quantity_per_item: 1 diff --git a/test/fixtures/orders.yml b/test/fixtures/orders.yml new file mode 100644 index 0000000000..18b72e3a4a --- /dev/null +++ b/test/fixtures/orders.yml @@ -0,0 +1,25 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + email: MyString + mailing_address: MyString + name_on_card: MyString + credit_card_num: 1 + credit_card_exp_month: 1 + credit_card_exp_year: 1 + cvv_num: 1 + zipcode: 1 + status: false + +two: + name: MyString + email: MyString + mailing_address: MyString + name_on_card: MyString + credit_card_num: 1 + credit_card_exp_month: 1 + credit_card_exp_year: 1 + cvv_num: 1 + zipcode: 1 + status: false diff --git a/test/fixtures/reviews.yml b/test/fixtures/reviews.yml new file mode 100644 index 0000000000..c5182ba521 --- /dev/null +++ b/test/fixtures/reviews.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + description: MyString + rating: 1 + +two: + description: MyString + rating: 1 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000..c6ff5ad19a --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,17 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + uid: 1 + name: MyString + nickname: MyString + email: MyString + image_url: MyString + provider: MyString + +two: + uid: 1 + name: MyString + nickname: MyString + email: MyString + image_url: MyString + provider: MyString diff --git a/test/models/item_test.rb b/test/models/item_test.rb new file mode 100644 index 0000000000..9573bd9313 --- /dev/null +++ b/test/models/item_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Item do + let(:item) { Item.new } + + it "must be valid" do + value(item).must_be :valid? + end +end diff --git a/test/models/order_test.rb b/test/models/order_test.rb new file mode 100644 index 0000000000..df80f10fb6 --- /dev/null +++ b/test/models/order_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Order do + let(:order) { Order.new } + + it "must be valid" do + value(order).must_be :valid? + end +end diff --git a/test/models/orderitem_test.rb b/test/models/orderitem_test.rb new file mode 100644 index 0000000000..b8bc7d17d6 --- /dev/null +++ b/test/models/orderitem_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Orderitem do + let(:orderitem) { Orderitem.new } + + it "must be valid" do + value(orderitem).must_be :valid? + end +end diff --git a/test/models/review_test.rb b/test/models/review_test.rb new file mode 100644 index 0000000000..ce8378a033 --- /dev/null +++ b/test/models/review_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe Review do + let(:review) { Review.new } + + it "must be valid" do + value(review).must_be :valid? + end +end diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000000..cc862ac2d9 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe User do + let(:user) { User.new } + + it "must be valid" do + value(user).must_be :valid? + end +end From afa206f41f716f019ea00a74048cdf52a083724e Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Thu, 18 Oct 2018 15:16:53 -0700 Subject: [PATCH 003/281] Formatting form_with --- config/initializers/action_view.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 config/initializers/action_view.rb diff --git a/config/initializers/action_view.rb b/config/initializers/action_view.rb new file mode 100644 index 0000000000..142d382f87 --- /dev/null +++ b/config/initializers/action_view.rb @@ -0,0 +1 @@ +Rails.application.config.action_view.form_with_generates_remote_forms = false From 88f1e51753589e62c4a6570a74ae4f34edf0aafb Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Thu, 18 Oct 2018 15:29:38 -0700 Subject: [PATCH 004/281] Setting up relationships for tables --- app/models/item.rb | 4 ++++ app/models/order.rb | 2 ++ app/models/orderitem.rb | 2 ++ app/models/review.rb | 2 ++ app/models/user.rb | 3 +++ 5 files changed, 13 insertions(+) diff --git a/app/models/item.rb b/app/models/item.rb index 809e23f848..f95e70b7ad 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -1,2 +1,6 @@ class Item < ApplicationRecord + belongs_to :user + has_many :orderitems + has_many :reviews + end diff --git a/app/models/order.rb b/app/models/order.rb index 10281b3450..84009764a6 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,2 +1,4 @@ class Order < ApplicationRecord + belongs_to :user + has_many :orderitems end diff --git a/app/models/orderitem.rb b/app/models/orderitem.rb index ebe5c835d9..ad5fc385ba 100644 --- a/app/models/orderitem.rb +++ b/app/models/orderitem.rb @@ -1,2 +1,4 @@ class Orderitem < ApplicationRecord + belongs_to :order + belongs_to :item end diff --git a/app/models/review.rb b/app/models/review.rb index b2ca4935ed..7c6c923e34 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -1,2 +1,4 @@ class Review < ApplicationRecord + belongs_to :item + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index 379658a509..ee1f3941f6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,5 @@ class User < ApplicationRecord + has_many :items + has_many :orders + has_many :reviews end From 72d98d9b04664407b97f5377c8e55c03803f2ead Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Thu, 18 Oct 2018 15:37:24 -0700 Subject: [PATCH 005/281] Adding controllers for all tables --- app/assets/javascripts/homepage.js | 2 ++ app/assets/javascripts/items.js | 2 ++ app/assets/javascripts/orderitems.js | 2 ++ app/assets/javascripts/orders.js | 2 ++ app/assets/javascripts/reviews.js | 2 ++ app/assets/javascripts/sessions.js | 2 ++ app/assets/javascripts/users.js | 2 ++ app/assets/stylesheets/homepage.scss | 3 +++ app/assets/stylesheets/items.scss | 3 +++ app/assets/stylesheets/orderitems.scss | 3 +++ app/assets/stylesheets/orders.scss | 3 +++ app/assets/stylesheets/reviews.scss | 3 +++ app/assets/stylesheets/sessions.scss | 3 +++ app/assets/stylesheets/users.scss | 3 +++ app/controllers/homepage_controller.rb | 2 ++ app/controllers/items_controller.rb | 2 ++ app/controllers/orderitems_controller.rb | 2 ++ app/controllers/orders_controller.rb | 2 ++ app/controllers/reviews_controller.rb | 2 ++ app/controllers/sessions_controller.rb | 2 ++ app/controllers/users_controller.rb | 2 ++ app/helpers/homepage_helper.rb | 2 ++ app/helpers/items_helper.rb | 2 ++ app/helpers/orderitems_helper.rb | 2 ++ app/helpers/orders_helper.rb | 2 ++ app/helpers/reviews_helper.rb | 2 ++ app/helpers/sessions_helper.rb | 2 ++ app/helpers/users_helper.rb | 2 ++ app/models/orderitem.rb | 4 ---- db/migrate/20181018213025_create_orderitems.rb | 9 --------- test/controllers/homepage_controller_test.rb | 7 +++++++ test/controllers/items_controller_test.rb | 7 +++++++ test/controllers/orderitems_controller_test.rb | 7 +++++++ test/controllers/orders_controller_test.rb | 7 +++++++ test/controllers/reviews_controller_test.rb | 7 +++++++ test/controllers/sessions_controller_test.rb | 7 +++++++ test/controllers/users_controller_test.rb | 7 +++++++ test/fixtures/orderitems.yml | 7 ------- test/models/orderitem_test.rb | 9 --------- 39 files changed, 112 insertions(+), 29 deletions(-) create mode 100644 app/assets/javascripts/homepage.js create mode 100644 app/assets/javascripts/items.js create mode 100644 app/assets/javascripts/orderitems.js create mode 100644 app/assets/javascripts/orders.js create mode 100644 app/assets/javascripts/reviews.js create mode 100644 app/assets/javascripts/sessions.js create mode 100644 app/assets/javascripts/users.js create mode 100644 app/assets/stylesheets/homepage.scss create mode 100644 app/assets/stylesheets/items.scss create mode 100644 app/assets/stylesheets/orderitems.scss create mode 100644 app/assets/stylesheets/orders.scss create mode 100644 app/assets/stylesheets/reviews.scss create mode 100644 app/assets/stylesheets/sessions.scss create mode 100644 app/assets/stylesheets/users.scss create mode 100644 app/controllers/homepage_controller.rb create mode 100644 app/controllers/items_controller.rb create mode 100644 app/controllers/orderitems_controller.rb create mode 100644 app/controllers/orders_controller.rb create mode 100644 app/controllers/reviews_controller.rb create mode 100644 app/controllers/sessions_controller.rb create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/homepage_helper.rb create mode 100644 app/helpers/items_helper.rb create mode 100644 app/helpers/orderitems_helper.rb create mode 100644 app/helpers/orders_helper.rb create mode 100644 app/helpers/reviews_helper.rb create mode 100644 app/helpers/sessions_helper.rb create mode 100644 app/helpers/users_helper.rb delete mode 100644 app/models/orderitem.rb delete mode 100644 db/migrate/20181018213025_create_orderitems.rb create mode 100644 test/controllers/homepage_controller_test.rb create mode 100644 test/controllers/items_controller_test.rb create mode 100644 test/controllers/orderitems_controller_test.rb create mode 100644 test/controllers/orders_controller_test.rb create mode 100644 test/controllers/reviews_controller_test.rb create mode 100644 test/controllers/sessions_controller_test.rb create mode 100644 test/controllers/users_controller_test.rb delete mode 100644 test/fixtures/orderitems.yml delete mode 100644 test/models/orderitem_test.rb diff --git a/app/assets/javascripts/homepage.js b/app/assets/javascripts/homepage.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/homepage.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/items.js b/app/assets/javascripts/items.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/items.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/orderitems.js b/app/assets/javascripts/orderitems.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orderitems.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/orders.js b/app/assets/javascripts/orders.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/orders.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/reviews.js b/app/assets/javascripts/reviews.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/reviews.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/sessions.js b/app/assets/javascripts/sessions.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/sessions.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/users.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/homepage.scss b/app/assets/stylesheets/homepage.scss new file mode 100644 index 0000000000..9027e07a04 --- /dev/null +++ b/app/assets/stylesheets/homepage.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the homepage 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/items.scss b/app/assets/stylesheets/items.scss new file mode 100644 index 0000000000..49e86485cf --- /dev/null +++ b/app/assets/stylesheets/items.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the items 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/orderitems.scss b/app/assets/stylesheets/orderitems.scss new file mode 100644 index 0000000000..3ae284dd37 --- /dev/null +++ b/app/assets/stylesheets/orderitems.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the orderitems 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/orders.scss b/app/assets/stylesheets/orders.scss new file mode 100644 index 0000000000..3b0428a94e --- /dev/null +++ b/app/assets/stylesheets/orders.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the orders 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/reviews.scss b/app/assets/stylesheets/reviews.scss new file mode 100644 index 0000000000..6ea2454d26 --- /dev/null +++ b/app/assets/stylesheets/reviews.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reviews 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/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000000..7bef9cf826 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sessions 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/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000000..1efc835ccd --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the users 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/homepage_controller.rb b/app/controllers/homepage_controller.rb new file mode 100644 index 0000000000..73c66a44a8 --- /dev/null +++ b/app/controllers/homepage_controller.rb @@ -0,0 +1,2 @@ +class HomepageController < ApplicationController +end diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb new file mode 100644 index 0000000000..5c818d7567 --- /dev/null +++ b/app/controllers/items_controller.rb @@ -0,0 +1,2 @@ +class ItemsController < ApplicationController +end diff --git a/app/controllers/orderitems_controller.rb b/app/controllers/orderitems_controller.rb new file mode 100644 index 0000000000..bcac78bc17 --- /dev/null +++ b/app/controllers/orderitems_controller.rb @@ -0,0 +1,2 @@ +class OrderitemsController < ApplicationController +end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb new file mode 100644 index 0000000000..8a0e3659ae --- /dev/null +++ b/app/controllers/orders_controller.rb @@ -0,0 +1,2 @@ +class OrdersController < ApplicationController +end diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb new file mode 100644 index 0000000000..b3d77cc1c3 --- /dev/null +++ b/app/controllers/reviews_controller.rb @@ -0,0 +1,2 @@ +class ReviewsController < ApplicationController +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000000..16d11b5710 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,2 @@ +class SessionsController < ApplicationController +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000..3e74dea87f --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,2 @@ +class UsersController < ApplicationController +end diff --git a/app/helpers/homepage_helper.rb b/app/helpers/homepage_helper.rb new file mode 100644 index 0000000000..c5bbfe518f --- /dev/null +++ b/app/helpers/homepage_helper.rb @@ -0,0 +1,2 @@ +module HomepageHelper +end diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb new file mode 100644 index 0000000000..cff0c9fe21 --- /dev/null +++ b/app/helpers/items_helper.rb @@ -0,0 +1,2 @@ +module ItemsHelper +end diff --git a/app/helpers/orderitems_helper.rb b/app/helpers/orderitems_helper.rb new file mode 100644 index 0000000000..c74e407d1c --- /dev/null +++ b/app/helpers/orderitems_helper.rb @@ -0,0 +1,2 @@ +module OrderitemsHelper +end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb new file mode 100644 index 0000000000..443227fd48 --- /dev/null +++ b/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/app/helpers/reviews_helper.rb b/app/helpers/reviews_helper.rb new file mode 100644 index 0000000000..682b7b1abc --- /dev/null +++ b/app/helpers/reviews_helper.rb @@ -0,0 +1,2 @@ +module ReviewsHelper +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000000..309f8b2eb3 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000000..2310a240d7 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/orderitem.rb b/app/models/orderitem.rb deleted file mode 100644 index ad5fc385ba..0000000000 --- a/app/models/orderitem.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Orderitem < ApplicationRecord - belongs_to :order - belongs_to :item -end diff --git a/db/migrate/20181018213025_create_orderitems.rb b/db/migrate/20181018213025_create_orderitems.rb deleted file mode 100644 index 7ee5d5e65a..0000000000 --- a/db/migrate/20181018213025_create_orderitems.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateOrderitems < ActiveRecord::Migration[5.2] - def change - create_table :orderitems do |t| - t.integer :quantity_per_item - - t.timestamps - end - end -end diff --git a/test/controllers/homepage_controller_test.rb b/test/controllers/homepage_controller_test.rb new file mode 100644 index 0000000000..3817f59819 --- /dev/null +++ b/test/controllers/homepage_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe HomepageController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/items_controller_test.rb b/test/controllers/items_controller_test.rb new file mode 100644 index 0000000000..1cd4f6cc6b --- /dev/null +++ b/test/controllers/items_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe ItemsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/orderitems_controller_test.rb b/test/controllers/orderitems_controller_test.rb new file mode 100644 index 0000000000..16f4fb42b6 --- /dev/null +++ b/test/controllers/orderitems_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe OrderitemsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/orders_controller_test.rb b/test/controllers/orders_controller_test.rb new file mode 100644 index 0000000000..68784595f3 --- /dev/null +++ b/test/controllers/orders_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe OrdersController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/reviews_controller_test.rb b/test/controllers/reviews_controller_test.rb new file mode 100644 index 0000000000..386065239a --- /dev/null +++ b/test/controllers/reviews_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe ReviewsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 0000000000..c2632a720b --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe SessionsController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000000..89decb54e0 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +describe UsersController do + # it "must be a real test" do + # flunk "Need real tests" + # end +end diff --git a/test/fixtures/orderitems.yml b/test/fixtures/orderitems.yml deleted file mode 100644 index fee675af78..0000000000 --- a/test/fixtures/orderitems.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -one: - quantity_per_item: 1 - -two: - quantity_per_item: 1 diff --git a/test/models/orderitem_test.rb b/test/models/orderitem_test.rb deleted file mode 100644 index b8bc7d17d6..0000000000 --- a/test/models/orderitem_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "test_helper" - -describe Orderitem do - let(:orderitem) { Orderitem.new } - - it "must be valid" do - value(orderitem).must_be :valid? - end -end From 0a171ea3839e760bcc4f52f02e251edaf47cffe1 Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Thu, 18 Oct 2018 16:13:08 -0700 Subject: [PATCH 006/281] Added homepage controller --- app/controllers/homepage_controller.rb | 2 ++ app/views/homepage/index.html.erb | 3 +++ config/routes.rb | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 app/views/homepage/index.html.erb diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb index 73c66a44a8..e09cc6e590 100644 --- a/app/controllers/homepage_controller.rb +++ b/app/controllers/homepage_controller.rb @@ -1,2 +1,4 @@ class HomepageController < ApplicationController + def index + end end diff --git a/app/views/homepage/index.html.erb b/app/views/homepage/index.html.erb new file mode 100644 index 0000000000..0eb10e9dcd --- /dev/null +++ b/app/views/homepage/index.html.erb @@ -0,0 +1,3 @@ +
+

Welcome to Cute Stuff o-rama

+
diff --git a/config/routes.rb b/config/routes.rb index 787824f888..aab5d5bc52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,6 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + root 'homepage#index' + resources :users, :orders, :orderitems, :items, :reviews + end From 3e38ae287152a25ed974ad1657525a3d70a473e2 Mon Sep 17 00:00:00 2001 From: Kat Perreira Date: Fri, 19 Oct 2018 05:41:05 -0700 Subject: [PATCH 007/281] Added CRUD to items controller --- app/controllers/items_controller.rb | 66 ++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 5c818d7567..03c8a40dbc 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -1,2 +1,66 @@ class ItemsController < ApplicationController -end + + + def index + @items = Item.all + end + + def edit + @item = Item.find_by(id: params[:id]) + end + + def new + @item = Item.new + end + + def destroy + item = Item.find_by(id: params[:id]) + item.destroy + redirect_to root_path + end + + # a name must be unique + def create + not_unique_name = Item.find_by(name: params[:name]) + if not_unique_name + flash[:error]= "A Problem Occured: item with this name already exists" + else + filtered_params = item_params() + @item = Item.new(filtered_params) + save_success = @item.save + if save_success + redirect_to items_path + else + flash.now[:error] = "Invalid item entry" + render :new, status: :bad_request + end + end + end + + def show + item_id = params[:id] + @item = Item.find_by(id: item_id) + if @item.nil? + head :not_found + end + end + + def update + @item = Item.find(params[:id]) + @item.update(item_params) + redirect_to items_path + end + + private + + def item_params + return params.require(:item).permit( + :name, + :category, + :price, + :quantity_available, + :description + :active + ) + end + end From a68269409dc07477d692efed171620d9eb168192 Mon Sep 17 00:00:00 2001 From: Kat Perreira Date: Fri, 19 Oct 2018 06:11:53 -0700 Subject: [PATCH 008/281] added show and index to items --- app/controllers/items_controller.rb | 4 +++- app/views/items/index.html.erb | 17 +++++++++++++++++ app/views/items/show.html.erb | 7 +++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/views/items/index.html.erb create mode 100644 app/views/items/show.html.erb diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 03c8a40dbc..eee87a80dc 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -59,8 +59,10 @@ def item_params :category, :price, :quantity_available, - :description + :description, + :image, :active + ) end end diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb new file mode 100644 index 0000000000..43d683dae9 --- /dev/null +++ b/app/views/items/index.html.erb @@ -0,0 +1,17 @@ +
+

All Items

+
+ + +<% @items.each do |item| %> + + +<%= item.name %> +<%= item.image %> +<%= item.price %> +<%= item.quantitiy_avaliable %> +<%= item.avg_rating %> +<%= item.description %> +<% end %> + + diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb new file mode 100644 index 0000000000..2f0e5bca12 --- /dev/null +++ b/app/views/items/show.html.erb @@ -0,0 +1,7 @@ +

Product Details

+<%= @item.name %> +<%= @item.catagory %> +<%= @item.price %> +<%= @item.image %> +<%= @item.avg_rating %> +<%= @item.description %> From 8550cfed3c70b5102ff217bac9838330050e0379 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 09:58:42 -0700 Subject: [PATCH 009/281] added method to build user account from github, working on routes and controller logic for users --- app/controllers/users_controller.rb | 102 ++++++++++++++++++++++++++++ app/models/user.rb | 4 ++ config/routes.rb | 9 ++- 3 files changed, 113 insertions(+), 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3e74dea87f..4f194ccfd9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,2 +1,104 @@ class UsersController < ApplicationController + + before_action :find_user, only: :show + + #PUT THIS IN METHOD IN MODEL? + before_action :find_user_products, only: :shop + before_action :find_user_orders, only: :orders + + #UNECESSARY???? + def index + @users = User.all + end + + #PROFILE, PURCHASE HISTORY + def show + head: not_found unless @user + # render 'layouts/invalid_page', status: :not_found + end + + def shop + if !@user_products + #guest user + #render 'layouts/forbidden', status: 400? + end + #in view: if @user_products = [], secondary view: become a merchant! + #else, just show products and add products button + #product show should have conditional for editing products + end + + def orders + if !@user_orders + #guest user + #render 'layouts/forbidden', status: 400? + end + #in view: if @user_products = [], secondary view: become a merchant! + #else, just show products and add products button + #product show should have conditional for editing products + end + + # def new + # @user = User.new() + # end + # + # def create + # filtered_user_params = user_params() + # @user = User.new(filtered_user_params) + # + # if @user.save + # session[:user_id] = @user.id + # flash[:success] = "User #{@user.username} has successfully signed up and logged in!" + # redirect_to root_path + # else + # flash.now[:failure] = "Error: user could not be saved." + # render :new, status: 400 + # end + # end + + # def destroy + # if @user.destroy + # flash[:success] = "User #{@user.id} has been deleted" + # redirect_to root_path + # else + # flash[:failure] = "User #{@user.id} could not be deleted. Sorry about it.¯\\_(ツ)_/¯" + # redirect_back fallback_location: root_path + # end + # end + + private + + #strong params + def user_params + return params.require(:user).permit( + :name, + :nickname, + :email, + :image_url, + :uid, + :provider + ) + end + + def find_user + @user = User.find_by(id: params[:id]) + end + + #PUT IN MODEL? + def find_user_products + if session[:user_id] + @user_products = User.find_by(id: params[:user_id]).products + elsif session[:guest_user_id] + @user_products = nil + end + end + + #PUT IN MODEL? + def find_user_orders + if session[:user_id] + @user_orders = User.find_by(id: params[:user_id]).orders + elsif session[:guest_user_id] + @user_orders = nil + end + end + end diff --git a/app/models/user.rb b/app/models/user.rb index ee1f3941f6..09374be206 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,4 +2,8 @@ class User < ApplicationRecord has_many :items has_many :orders has_many :reviews + + def self.build_from_github(auth_hash) + user = User.new(provider: auth_hash['provider'], uid: auth_hash['uid'], nickname: auth_hash['info']['nickname'], name: auth_hash['info']['name'], email: auth_hash['info']['email'], image_url: auto_hash['info']['image']) + end end diff --git a/config/routes.rb b/config/routes.rb index aab5d5bc52..018795c919 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,11 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root 'homepage#index' - resources :users, :orders, :orderitems, :items, :reviews - + resources :users, only: [:index, :show, :shop] + + resources :orders, :orderitems, :items, :reviews + + get '/shop', to: 'user#shop', as: shop_path + + get '/history', to: 'user#orders', as: orders_path end From b56d6085cd8f720cdda1ec6b4df4eb92042a95ab Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Fri, 19 Oct 2018 10:24:24 -0700 Subject: [PATCH 010/281] OAuth set up --- .gitignore | 3 ++ Gemfile | 5 +++ Gemfile.lock | 28 ++++++++++++ app/assets/stylesheets/application.scss | 4 ++ app/controllers/application_controller.rb | 11 +++++ app/controllers/sessions_controller.rb | 34 ++++++++++++++ app/views/layouts/application.html.erb | 55 ++++++++++++++++++++++- config/initializers/omniauth.rb | 3 ++ config/routes.rb | 4 +- 9 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 config/initializers/omniauth.rb diff --git a/.gitignore b/.gitignore index 18b43c9cd2..f53c1dab15 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +#Ignore OAuth info +.env diff --git a/Gemfile b/Gemfile index 6219256bd8..dd451b9002 100644 --- a/Gemfile +++ b/Gemfile @@ -48,6 +48,7 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' + gem 'dotenv-rails' end group :test do @@ -79,3 +80,7 @@ group :test do gem 'minitest-rails' gem 'minitest-reporters' end + +# Setting up for OAuth +gem "omniauth" +gem "omniauth-github" diff --git a/Gemfile.lock b/Gemfile.lock index 51100b2a1d..6ffb22fbfa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,8 +81,14 @@ GEM concurrent-ruby (1.0.5) crass (1.0.4) debug_inspector (0.0.3) + dotenv (2.5.0) + dotenv-rails (2.5.0) + dotenv (= 2.5.0) + railties (>= 3.2, < 6.0) erubi (1.7.1) execjs (2.7.0) + faraday (0.15.3) + multipart-post (>= 1.2, < 3) ffi (1.9.25) formatador (0.2.5) globalid (0.4.1) @@ -100,6 +106,7 @@ GEM guard-minitest (2.4.6) guard-compat (~> 1.2) minitest (>= 3.0) + hashie (3.5.7) i18n (1.1.1) concurrent-ruby (~> 1.0) io-like (0.3.0) @@ -113,6 +120,7 @@ GEM jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks + jwt (2.1.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -140,6 +148,8 @@ GEM ruby-progressbar msgpack (1.2.4) multi_json (1.13.1) + multi_xml (0.6.0) + multipart-post (2.0.0) nenv (0.3.0) nio4r (2.3.1) nokogiri (1.8.5) @@ -147,6 +157,21 @@ GEM notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) + oauth2 (1.4.1) + faraday (>= 0.8, < 0.16.0) + jwt (>= 1.0, < 3.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.8.1) + hashie (>= 3.4.6, < 3.6.0) + rack (>= 1.6.2, < 3) + omniauth-github (1.3.0) + omniauth (~> 1.5) + omniauth-oauth2 (>= 1.4.0, < 2.0) + omniauth-oauth2 (1.5.0) + oauth2 (~> 1.1) + omniauth (~> 1.2) pg (1.1.3) popper_js (1.14.3) pry (0.11.3) @@ -249,6 +274,7 @@ DEPENDENCIES byebug capybara (>= 2.15) chromedriver-helper + dotenv-rails guard guard-minitest jbuilder (~> 2.5) @@ -257,6 +283,8 @@ DEPENDENCIES listen (>= 3.0.5, < 3.2) minitest-rails minitest-reporters + omniauth + omniauth-github pg (>= 0.18, < 2.0) pry-rails puma (~> 3.11) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8b1701e581..c6358f9cb1 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,3 +16,7 @@ @import "bootstrap"; /* Import scss content */ @import "**/*"; + +header > ul > li{ + list-style: none; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d12ab..bd0a0dc794 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,13 @@ class ApplicationController < ActionController::Base + protect_from_forgery with: :exception + + # before_action :create_guest_user + before_action :find_user + + private + def find_user + if session[:user_id] + @login_user = User.find_by(id: session[:user_id]) + end + end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 16d11b5710..b73303ccbc 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,2 +1,36 @@ class SessionsController < ApplicationController + def create + auth_hash = request.env['omniauth.auth'] + # raise + user = User.find_by(uid: auth_hash[:uid], provider: auth_hash[:provider]) + + + if user + session[:user_id] = user.id + else + new_user = User.new( + name: auth_hash['info']['name'], + nickname: auth_hash['info']['nickname'], + email: auth_hash['info']['email'], + image_url: auth_hash['info']['image'], + uid: auth_hash['uid'], + provider: auth_hash['provider'], + created_at: Time.now + ) + + if new_user.save + session[:user_id] = new_user.id + else + redirect_to root_path + return + end + end + redirect_to root_path + + end + + def logout + session[:user_id] = nil + redirect_to root_path + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f18f1b6820..f071e4f9b9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,59 @@ - <%= yield %> +
+
    +
  • + <%= link_to "Log Out", logout_path, method: :post %> +
  • +
  • + <%= link_to "Log In", "/auth/github" %> +
  • +
+ +

Store Name

+ +
+ +
+ <%= yield %> +
+ +
+
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 0000000000..fd4416122a --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,3 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" +end diff --git a/config/routes.rb b/config/routes.rb index aab5d5bc52..f12f493459 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,5 +2,7 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root 'homepage#index' resources :users, :orders, :orderitems, :items, :reviews - + + get "/auth/:provider/callback", to: "sessions#create" + post '/logout', to: 'sessions#logout', as: 'logout' end From 7faf992d9283cb4a7e86029d8df473883f3f2100 Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Fri, 19 Oct 2018 10:45:10 -0700 Subject: [PATCH 011/281] application.html.erb displaying logged in user.nickname --- app/controllers/application_controller.rb | 12 +----------- app/views/layouts/application.html.erb | 6 ++++++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bd0a0dc794..a90db2e4ad 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,13 +1,3 @@ class ApplicationController < ActionController::Base - protect_from_forgery with: :exception - - # before_action :create_guest_user - before_action :find_user - - private - def find_user - if session[:user_id] - @login_user = User.find_by(id: session[:user_id]) - end - end + end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f071e4f9b9..2aeacb668c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,6 +11,12 @@
+ + <% if session[:user_id] %> + <% current_user = User.find_by(id: session[:user_id]) %> + <%= current_user.nickname %> + <% end %> +
  • <%= link_to "Log Out", logout_path, method: :post %> From 7921bdf64860ad4a4ab9c852d692f7100aa7b351 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 11:29:22 -0700 Subject: [PATCH 012/281] moved finding user into application controller and used session[user_id] instead of params[id] plus @current_user instead of @user --- app/controllers/application_controller.rb | 8 ++++++++ app/controllers/users_controller.rb | 11 ++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d12ab..1927f71987 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,10 @@ class ApplicationController < ActionController::Base + + before_action :find_current_user + + private + + def find_current_user + @current_user = User.find_by(id: session[:user_id]) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4f194ccfd9..0a0e9f457b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,6 @@ class UsersController < ApplicationController - before_action :find_user, only: :show + # before_action :find_user, only: :show #PUT THIS IN METHOD IN MODEL? before_action :find_user_products, only: :shop @@ -13,7 +13,8 @@ def index #PROFILE, PURCHASE HISTORY def show - head: not_found unless @user + # head: not_found unless @user + head: not_found unless @current_user # render 'layouts/invalid_page', status: :not_found end @@ -79,9 +80,9 @@ def user_params ) end - def find_user - @user = User.find_by(id: params[:id]) - end + # def find_user + # @user = User.find_by(id: params[:id]) + # end #PUT IN MODEL? def find_user_products From b08401e6bdef2bb3c806c681c885e954120b06ab Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 11:31:13 -0700 Subject: [PATCH 013/281] refactored find_user_products and find_user_orders --- app/controllers/users_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0a0e9f457b..9a446184ba 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -86,8 +86,8 @@ def user_params #PUT IN MODEL? def find_user_products - if session[:user_id] - @user_products = User.find_by(id: params[:user_id]).products + if @current_user + @user_products = User.find_by(id: session[:user_id]).products elsif session[:guest_user_id] @user_products = nil end @@ -95,8 +95,8 @@ def find_user_products #PUT IN MODEL? def find_user_orders - if session[:user_id] - @user_orders = User.find_by(id: params[:user_id]).orders + if @current_user + @user_orders = User.find_by(id: session[:user_id]).orders elsif session[:guest_user_id] @user_orders = nil end From 29ec6b4e9e990ca9892104f07fa895533c88e82c Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 14:22:25 -0700 Subject: [PATCH 014/281] new applicaitioncontroller method find_all_merchants --- app/controllers/application_controller.rb | 7 ++++++- app/controllers/users_controller.rb | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1927f71987..2be97436e7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,8 +3,13 @@ class ApplicationController < ActionController::Base before_action :find_current_user private - + def find_current_user @current_user = User.find_by(id: session[:user_id]) end + + #find all merchants + def find_all_merchants + @merchants = User.where(products: []) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9a446184ba..3e7b7ee46f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,8 +1,7 @@ class UsersController < ApplicationController # before_action :find_user, only: :show - - #PUT THIS IN METHOD IN MODEL? + before_action :find_user_products, only: :shop before_action :find_user_orders, only: :orders From 4a0710e72f5344a9ade1ddd1bd3397ee7c245eaf Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 14:29:03 -0700 Subject: [PATCH 015/281] changes users routes --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 018795c919..c0050cf5c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root 'homepage#index' - resources :users, only: [:index, :show, :shop] + resources :users, only: [:index, :show, :shop, :orders] resources :orders, :orderitems, :items, :reviews From edf44e45cad880ef0249426aaf27c9c79030c2ef Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Fri, 19 Oct 2018 15:39:03 -0700 Subject: [PATCH 016/281] Format for login/logout --- app/views/layouts/application.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2aeacb668c..53dfbb8eea 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,7 +14,9 @@ <% if session[:user_id] %> <% current_user = User.find_by(id: session[:user_id]) %> - <%= current_user.nickname %> +

    + Welcome, <%= current_user.nickname %> +

    <% end %>
      From f2eddb7b4acf68d7570c8825581438638d340c3e Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 15:40:11 -0700 Subject: [PATCH 017/281] commented out stuff --- app/controllers/application_controller.rb | 3 +- app/controllers/users_controller.rb | 71 +---------------------- app/models/user.rb | 6 +- config/routes.rb | 4 +- 4 files changed, 7 insertions(+), 77 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2be97436e7..404edafbf7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,11 +1,12 @@ class ApplicationController < ActionController::Base before_action :find_current_user + before_action :find_all_merchants private def find_current_user - @current_user = User.find_by(id: session[:user_id]) + @current_user |= User.find_by(id: session[:user_id]) end #find all merchants diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3e7b7ee46f..6a9bf2af1c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,14 +1,7 @@ class UsersController < ApplicationController - # before_action :find_user, only: :show - before_action :find_user_products, only: :shop - before_action :find_user_orders, only: :orders - #UNECESSARY???? - def index - @users = User.all - end #PROFILE, PURCHASE HISTORY def show @@ -18,53 +11,8 @@ def show end def shop - if !@user_products - #guest user - #render 'layouts/forbidden', status: 400? - end - #in view: if @user_products = [], secondary view: become a merchant! - #else, just show products and add products button - #product show should have conditional for editing products - end - - def orders - if !@user_orders - #guest user - #render 'layouts/forbidden', status: 400? - end - #in view: if @user_products = [], secondary view: become a merchant! - #else, just show products and add products button - #product show should have conditional for editing products end - # def new - # @user = User.new() - # end - # - # def create - # filtered_user_params = user_params() - # @user = User.new(filtered_user_params) - # - # if @user.save - # session[:user_id] = @user.id - # flash[:success] = "User #{@user.username} has successfully signed up and logged in!" - # redirect_to root_path - # else - # flash.now[:failure] = "Error: user could not be saved." - # render :new, status: 400 - # end - # end - - # def destroy - # if @user.destroy - # flash[:success] = "User #{@user.id} has been deleted" - # redirect_to root_path - # else - # flash[:failure] = "User #{@user.id} could not be deleted. Sorry about it.¯\\_(ツ)_/¯" - # redirect_back fallback_location: root_path - # end - # end - private #strong params @@ -79,26 +27,9 @@ def user_params ) end - # def find_user - # @user = User.find_by(id: params[:id]) - # end - #PUT IN MODEL? def find_user_products - if @current_user - @user_products = User.find_by(id: session[:user_id]).products - elsif session[:guest_user_id] - @user_products = nil - end - end - #PUT IN MODEL? - def find_user_orders - if @current_user - @user_orders = User.find_by(id: session[:user_id]).orders - elsif session[:guest_user_id] - @user_orders = nil - end + @user_products = User.find_by(@current_user).products end - end diff --git a/app/models/user.rb b/app/models/user.rb index 09374be206..75928e7f2b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,7 +3,7 @@ class User < ApplicationRecord has_many :orders has_many :reviews - def self.build_from_github(auth_hash) - user = User.new(provider: auth_hash['provider'], uid: auth_hash['uid'], nickname: auth_hash['info']['nickname'], name: auth_hash['info']['name'], email: auth_hash['info']['email'], image_url: auto_hash['info']['image']) - end + # def self.build_from_github(auth_hash) + # user = User.new(provider: auth_hash['provider'], uid: auth_hash['uid'], nickname: auth_hash['info']['nickname'], name: auth_hash['info']['name'], email: auth_hash['info']['email'], image_url: auto_hash['info']['image']) + # end end diff --git a/config/routes.rb b/config/routes.rb index c0050cf5c1..008c316ac4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,9 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root 'homepage#index' - resources :users, only: [:index, :show, :shop, :orders] + resources :users, only: [:show, :shop, :orders] resources :orders, :orderitems, :items, :reviews get '/shop', to: 'user#shop', as: shop_path - - get '/history', to: 'user#orders', as: orders_path end From ab83689534440f25bb7ee5faac51691bda12ec9a Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Fri, 19 Oct 2018 15:45:48 -0700 Subject: [PATCH 018/281] Merge conflict --- app/controllers/application_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a90db2e4ad..09705d12ab 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,2 @@ class ApplicationController < ActionController::Base - end From d0fd8275fd1f04ffab8109430261265b5dfa9b53 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 15:50:34 -0700 Subject: [PATCH 019/281] added find_searched_user to userscontroller --- app/controllers/users_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6a9bf2af1c..2da479c00b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,12 +1,13 @@ class UsersController < ApplicationController before_action :find_user_products, only: :shop + before_action :find_searched_user, only: :show #PROFILE, PURCHASE HISTORY def show # head: not_found unless @user - head: not_found unless @current_user + head: not_found unless @user # render 'layouts/invalid_page', status: :not_found end @@ -27,6 +28,10 @@ def user_params ) end + def find_searched_user + @user = User.find_by(id: params[:id]) + end + #PUT IN MODEL? def find_user_products From defdeddbe00c9d20cbe049a823feaf1a79a0de3a Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Fri, 19 Oct 2018 15:51:10 -0700 Subject: [PATCH 020/281] Merge conflict --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 6820ca23cb..d185705be2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,5 +8,5 @@ get "/auth/:provider/callback", to: "sessions#create" post '/logout', to: 'sessions#logout', as: 'logout' - get '/shop', to: 'user#shop', as: shop_path + # get '/shop', to: 'user#shop', as: shop_path end From 0108069f6c7c060f7975553314579093e4e37752 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 15:59:54 -0700 Subject: [PATCH 021/281] added require_login for applicationcontroller --- app/controllers/application_controller.rb | 8 ++++++++ app/controllers/users_controller.rb | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 404edafbf7..22a777d1d2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base before_action :find_current_user before_action :find_all_merchants + before_action :require_login, except: :index private @@ -13,4 +14,11 @@ def find_current_user def find_all_merchants @merchants = User.where(products: []) end + + def require_login + unless @current_user + flash[:failure] = "You must be logged in to do that." + redirect_to root_path + end + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2da479c00b..794a480fed 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -34,7 +34,6 @@ def find_searched_user #PUT IN MODEL? def find_user_products - @user_products = User.find_by(@current_user).products end end From cb3a4cce810346e033b7708a1855c5c73084a170 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 16:05:37 -0700 Subject: [PATCH 022/281] moved findign user products into model --- app/controllers/users_controller.rb | 6 ++---- app/models/user.rb | 7 +++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 794a480fed..7b1c1d5c48 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,8 +3,7 @@ class UsersController < ApplicationController before_action :find_user_products, only: :shop before_action :find_searched_user, only: :show - - #PROFILE, PURCHASE HISTORY + #PROFILE def show # head: not_found unless @user head: not_found unless @user @@ -32,8 +31,7 @@ def find_searched_user @user = User.find_by(id: params[:id]) end - #PUT IN MODEL? def find_user_products - @user_products = User.find_by(@current_user).products + @user_products = @user.find_products end end diff --git a/app/models/user.rb b/app/models/user.rb index 75928e7f2b..1a05b5a3cf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,4 +6,11 @@ class User < ApplicationRecord # def self.build_from_github(auth_hash) # user = User.new(provider: auth_hash['provider'], uid: auth_hash['uid'], nickname: auth_hash['info']['nickname'], name: auth_hash['info']['name'], email: auth_hash['info']['email'], image_url: auto_hash['info']['image']) # end + +private + + #instance method to find products for this user + def find_products + return self.products + end end From ff91f831c61ee7ba3ce747bd2015dcde2fbc9383 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Fri, 19 Oct 2018 16:13:18 -0700 Subject: [PATCH 023/281] Edit history so that orderitems were in fact created --- config/routes.rb | 2 +- db/migrate/20181018215421_add_shipped_to_orderitem.rb | 2 +- .../20181018215601_add_order_and_item_orderitem.rb | 4 ++-- db/schema.rb | 11 +++++------ 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 6820ca23cb..d185705be2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,5 +8,5 @@ get "/auth/:provider/callback", to: "sessions#create" post '/logout', to: 'sessions#logout', as: 'logout' - get '/shop', to: 'user#shop', as: shop_path + # get '/shop', to: 'user#shop', as: shop_path end diff --git a/db/migrate/20181018215421_add_shipped_to_orderitem.rb b/db/migrate/20181018215421_add_shipped_to_orderitem.rb index 0acb705f52..8493fb60fa 100644 --- a/db/migrate/20181018215421_add_shipped_to_orderitem.rb +++ b/db/migrate/20181018215421_add_shipped_to_orderitem.rb @@ -1,5 +1,5 @@ class AddShippedToOrderitem < ActiveRecord::Migration[5.2] def change - add_column :orderitems, :shipped, :boolean, default:false + add_column :order_items, :shipped, :boolean, default:false end end diff --git a/db/migrate/20181018215601_add_order_and_item_orderitem.rb b/db/migrate/20181018215601_add_order_and_item_orderitem.rb index aba45c23b3..a6f2fa1b05 100644 --- a/db/migrate/20181018215601_add_order_and_item_orderitem.rb +++ b/db/migrate/20181018215601_add_order_and_item_orderitem.rb @@ -1,6 +1,6 @@ class AddOrderAndItemOrderitem < ActiveRecord::Migration[5.2] def change - add_reference :orderitems, :order, foreign_key: true - add_reference :orderitems, :item, foreign_key: true + add_reference :order_items, :order, foreign_key: true + add_reference :order_items, :item, foreign_key: true end end diff --git a/db/schema.rb b/db/schema.rb index 58fd4e7265..d09e5670af 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -30,15 +30,14 @@ t.index ["user_id"], name: "index_items_on_user_id" end - create_table "orderitems", force: :cascade do |t| - t.integer "quantity_per_item" + create_table "order_items", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "shipped", default: false t.bigint "order_id" t.bigint "item_id" - t.index ["item_id"], name: "index_orderitems_on_item_id" - t.index ["order_id"], name: "index_orderitems_on_order_id" + t.index ["item_id"], name: "index_order_items_on_item_id" + t.index ["order_id"], name: "index_order_items_on_order_id" end create_table "orders", force: :cascade do |t| @@ -81,8 +80,8 @@ end add_foreign_key "items", "users" - add_foreign_key "orderitems", "items" - add_foreign_key "orderitems", "orders" + add_foreign_key "order_items", "items" + add_foreign_key "order_items", "orders" add_foreign_key "orders", "users" add_foreign_key "reviews", "items" add_foreign_key "reviews", "users" From 45d15c33d519f09614f43caf59ed75d1b42fad16 Mon Sep 17 00:00:00 2001 From: Kat Perreira Date: Fri, 19 Oct 2018 16:15:52 -0700 Subject: [PATCH 024/281] tookout something --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 6820ca23cb..d185705be2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,5 +8,5 @@ get "/auth/:provider/callback", to: "sessions#create" post '/logout', to: 'sessions#logout', as: 'logout' - get '/shop', to: 'user#shop', as: shop_path + # get '/shop', to: 'user#shop', as: shop_path end From e9f6531eaa0930eb4888e62585e95b63d55b5079 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Fri, 19 Oct 2018 16:18:07 -0700 Subject: [PATCH 025/281] updating migrations --- app/models/order_item.rb | 2 ++ db/migrate/20181018215000_create_order_items.rb | 8 ++++++++ test/fixtures/order_items.yml | 11 +++++++++++ test/models/order_item_test.rb | 9 +++++++++ 4 files changed, 30 insertions(+) create mode 100644 app/models/order_item.rb create mode 100644 db/migrate/20181018215000_create_order_items.rb create mode 100644 test/fixtures/order_items.yml create mode 100644 test/models/order_item_test.rb diff --git a/app/models/order_item.rb b/app/models/order_item.rb new file mode 100644 index 0000000000..acc6099fd0 --- /dev/null +++ b/app/models/order_item.rb @@ -0,0 +1,2 @@ +class OrderItem < ApplicationRecord +end diff --git a/db/migrate/20181018215000_create_order_items.rb b/db/migrate/20181018215000_create_order_items.rb new file mode 100644 index 0000000000..0e744b51f7 --- /dev/null +++ b/db/migrate/20181018215000_create_order_items.rb @@ -0,0 +1,8 @@ +class CreateOrderItems < ActiveRecord::Migration[5.2] + def change + create_table :order_items do |t| + + t.timestamps + end + end +end diff --git a/test/fixtures/order_items.yml b/test/fixtures/order_items.yml new file mode 100644 index 0000000000..dc3ee79b5d --- /dev/null +++ b/test/fixtures/order_items.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/order_item_test.rb b/test/models/order_item_test.rb new file mode 100644 index 0000000000..19a9bf8f58 --- /dev/null +++ b/test/models/order_item_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe OrderItem do + let(:order_item) { OrderItem.new } + + it "must be valid" do + value(order_item).must_be :valid? + end +end From a4acd28f34c201fb86b08a680e9cf9af62c6b07a Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 16:22:38 -0700 Subject: [PATCH 026/281] added user find_products --- app/models/user.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index 75928e7f2b..8f6e7a6ba5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,4 +6,11 @@ class User < ApplicationRecord # def self.build_from_github(auth_hash) # user = User.new(provider: auth_hash['provider'], uid: auth_hash['uid'], nickname: auth_hash['info']['nickname'], name: auth_hash['info']['name'], email: auth_hash['info']['email'], image_url: auto_hash['info']['image']) # end + + private + + #instance method to find products for this user + def find_products + return self.products + end end From 38b752cec795c5adc290d984ab1f836cfb32329f Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 16:23:32 -0700 Subject: [PATCH 027/281] added require_login in application_controller --- app/controllers/application_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 404edafbf7..22a777d1d2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base before_action :find_current_user before_action :find_all_merchants + before_action :require_login, except: :index private @@ -13,4 +14,11 @@ def find_current_user def find_all_merchants @merchants = User.where(products: []) end + + def require_login + unless @current_user + flash[:failure] = "You must be logged in to do that." + redirect_to root_path + end + end end From 867842af0874a4a3ed6aaff397c03e3c62d13182 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Fri, 19 Oct 2018 16:24:50 -0700 Subject: [PATCH 028/281] added find_user stuff to user --- app/controllers/users_controller.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2da479c00b..b42a153632 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,10 +3,8 @@ class UsersController < ApplicationController before_action :find_user_products, only: :shop before_action :find_searched_user, only: :show - - #PROFILE, PURCHASE HISTORY + #PROFILE def show - # head: not_found unless @user head: not_found unless @user # render 'layouts/invalid_page', status: :not_found end @@ -32,9 +30,7 @@ def find_searched_user @user = User.find_by(id: params[:id]) end - #PUT IN MODEL? def find_user_products - - @user_products = User.find_by(@current_user).products + @user_products = @user.find_products end end From 6c94c3af7809f82ae743265a300121a6ba80d3ce Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Fri, 19 Oct 2018 16:28:08 -0700 Subject: [PATCH 029/281] Resolve DB issues --- db/migrate/20181019232117_add_quantity_to_orderitems.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20181019232117_add_quantity_to_orderitems.rb diff --git a/db/migrate/20181019232117_add_quantity_to_orderitems.rb b/db/migrate/20181019232117_add_quantity_to_orderitems.rb new file mode 100644 index 0000000000..76dce75ade --- /dev/null +++ b/db/migrate/20181019232117_add_quantity_to_orderitems.rb @@ -0,0 +1,5 @@ +class AddQuantityToOrderitems < ActiveRecord::Migration[5.2] + def change + add_column :order_items, :quantity_per_item, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index d09e5670af..d796daa044 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_18_220256) do +ActiveRecord::Schema.define(version: 2018_10_19_232117) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -36,6 +36,7 @@ t.boolean "shipped", default: false t.bigint "order_id" t.bigint "item_id" + t.integer "quantity_per_item" t.index ["item_id"], name: "index_order_items_on_item_id" t.index ["order_id"], name: "index_order_items_on_order_id" end From c4fb4657847dd9c9e1756f06e2186023e1764234 Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Fri, 19 Oct 2018 22:25:38 -0700 Subject: [PATCH 030/281] Querying active merchants --- app/assets/stylesheets/application.scss | 18 ++++++++-- app/controllers/application_controller.rb | 9 +++-- app/views/layouts/application.html.erb | 41 ++++++++++++++--------- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index c6358f9cb1..a90251dbf3 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -17,6 +17,20 @@ /* Import scss content */ @import "**/*"; -header > ul > li{ - list-style: none; + +.navbar{ + background-color: none; + border-top: .25px solid lightgrey; + border-bottom: .25px solid lightgrey; +} + +.top_of_page > ul >li{ + list-style-type: none; + float: right; + padding-right: 30px; +} + +.top_of_page{ + // border-bottom: .25px solid lightgrey; + background-color: blue; } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 23f51f1bfa..65e0812db5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base before_action :find_current_user before_action :find_all_merchants - before_action :require_login, except: :index + # before_action :require_login, except: :index private @@ -13,9 +13,14 @@ def find_current_user #find all merchants def find_all_merchants - @merchants = User.where(products: []) + active_products = Item.where(active: true) + distinct_merchant_objects = active_products.select(:user_id).distinct + @merchant_ids = distinct_merchant_objects.map do |merchant| + merchant.user_id + end end + def require_login unless @current_user flash[:failure] = "You must be logged in to do that." diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 53dfbb8eea..f7061ec8d2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,25 +11,31 @@
      +
      +
        - <% if session[:user_id] %> - <% current_user = User.find_by(id: session[:user_id]) %> -

        - Welcome, <%= current_user.nickname %> -

        - <% end %> + <% if session[:user_id] %> + <% current_user = User.find_by(id: session[:user_id]) %> +
      • + Welcome, <%= current_user.nickname %> +

      • + <% end %> -
          -
        • - <%= link_to "Log Out", logout_path, method: :post %> -
        • -
        • - <%= link_to "Log In", "/auth/github" %> -
        • -
        + <% if session[:user_id] %> +
      • + <%= link_to "Log Out", logout_path, method: :post %> +
      • + <% else %> +
      • + <%= link_to "Log In", "/auth/github" %> +
      • + <% end %> +
      +

      Store Name

      -
    From 781606250becdcdc944b87dfbea67acfe598101c Mon Sep 17 00:00:00 2001 From: Kat Perreira Date: Sat, 20 Oct 2018 09:04:34 -0700 Subject: [PATCH 031/281] delete this merge --- app/controllers/application_controller.rb | 21 ++++++++++++++------- app/views/items/index.html.erb | 2 +- app/views/layouts/application.html.erb | 7 +++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 23f51f1bfa..637bd18658 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base before_action :find_current_user before_action :find_all_merchants - before_action :require_login, except: :index + # before_action :require_login, except: :index private @@ -11,15 +11,22 @@ def find_current_user @current_user |= User.find_by(id: session[:user_id]) end + #find all merchants + # @merchants = User.where(products: []) #find all merchants def find_all_merchants - @merchants = User.where(products: []) + active_products = Item.where(active: true) + distinct_merchant_objects = active_products.select(:user_id).distinct + @merchant_ids = distinct_merchant_objects.map do |merchant| + merchant.user_id + end end - def require_login - unless @current_user - flash[:failure] = "You must be logged in to do that." - redirect_to root_path + + def require_login + unless @current_user + flash[:failure] = "You must be logged in to do that." + redirect_to root_path + end end end -end diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb index 43d683dae9..16f155c889 100644 --- a/app/views/items/index.html.erb +++ b/app/views/items/index.html.erb @@ -9,7 +9,7 @@ <%= item.name %> <%= item.image %> <%= item.price %> -<%= item.quantitiy_avaliable %> +<%= item.quantity_available %> <%= item.avg_rating %> <%= item.description %> <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 53dfbb8eea..5ab224865e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -58,8 +58,11 @@ Merchants + <% @merchant_ids.each do |id| %> + <% merchant = User.find_by(id: id) %> + <%= merchant.nickname %> + <% end %> +
From 7650f03f37e01006797fdfe198e12d5db1103729 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sat, 20 Oct 2018 09:24:31 -0700 Subject: [PATCH 032/281] commented a few things out to get the items/show pages to work --- app/controllers/application_controller.rb | 2 +- app/views/items/show.html.erb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 23f51f1bfa..057b20dd6c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base before_action :find_current_user before_action :find_all_merchants - before_action :require_login, except: :index + # before_action :require_login, except: :index private diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 2f0e5bca12..7998d0387e 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -1,7 +1,7 @@

Product Details

-<%= @item.name %> -<%= @item.catagory %> -<%= @item.price %> +Item name: <%= @item.name %>
+Category: <%= @item.category %>
+Price: <%= @item.price.to_f %>
<%= @item.image %> <%= @item.avg_rating %> <%= @item.description %> From 138b3f71db52c77230582a549a7433019feaac9a Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sat, 20 Oct 2018 09:36:50 -0700 Subject: [PATCH 033/281] created strong params for orderitems --- app/controllers/orderitems_controller.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/orderitems_controller.rb b/app/controllers/orderitems_controller.rb index bcac78bc17..917efe55a6 100644 --- a/app/controllers/orderitems_controller.rb +++ b/app/controllers/orderitems_controller.rb @@ -1,2 +1,11 @@ class OrderitemsController < ApplicationController + + + + + private + def order_item_params + params.require(:order_item).permit(:shipped, :order_id, :item_id, :quantity_per_item) + end + end From 38d57aa6ef996757bb9909818fd62d7952f60a11 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sat, 20 Oct 2018 10:17:44 -0700 Subject: [PATCH 034/281] added method in application controllerto find a current order or create a new one --- app/controllers/application_controller.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 057b20dd6c..e72680af85 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,4 +22,13 @@ def require_login redirect_to root_path end end + + def current_order + if session[:order_id] + @order = Order.find(session[:order_id]) + else + @order = Order.new + end + end + end From 238662e29f9bb8b41f06bf447f251f629ea723bd Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Sat, 20 Oct 2018 10:22:09 -0700 Subject: [PATCH 035/281] Change category from string to foreign key --- app/assets/javascripts/category.js | 2 ++ app/assets/stylesheets/category.scss | 3 +++ app/controllers/category_controller.rb | 8 ++++++++ app/helpers/category_helper.rb | 2 ++ app/models/category.rb | 2 ++ app/views/category/show.html.erb | 12 ++++++++++++ app/views/layouts/application.html.erb | 14 ++++++-------- config/routes.rb | 2 +- db/migrate/20181020154501_create_categories.rb | 9 +++++++++ ...181020155307_change_type_column_for_category.rb | 5 +++++ .../20181020155504_add_item_type_to_category.rb | 5 +++++ .../20181020161333_delete_category_from_items.rb | 5 +++++ ...0181020161500_add_category_foreign_key_items.rb | 5 +++++ db/schema.rb | 12 ++++++++++-- db/seeds.rb | 12 +++++++++++- test/controllers/category_controller_test.rb | 7 +++++++ test/fixtures/categories.yml | 7 +++++++ test/models/category_test.rb | 9 +++++++++ 18 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 app/assets/javascripts/category.js create mode 100644 app/assets/stylesheets/category.scss create mode 100644 app/controllers/category_controller.rb create mode 100644 app/helpers/category_helper.rb create mode 100644 app/models/category.rb create mode 100644 app/views/category/show.html.erb create mode 100644 db/migrate/20181020154501_create_categories.rb create mode 100644 db/migrate/20181020155307_change_type_column_for_category.rb create mode 100644 db/migrate/20181020155504_add_item_type_to_category.rb create mode 100644 db/migrate/20181020161333_delete_category_from_items.rb create mode 100644 db/migrate/20181020161500_add_category_foreign_key_items.rb create mode 100644 test/controllers/category_controller_test.rb create mode 100644 test/fixtures/categories.yml create mode 100644 test/models/category_test.rb diff --git a/app/assets/javascripts/category.js b/app/assets/javascripts/category.js new file mode 100644 index 0000000000..dee720facd --- /dev/null +++ b/app/assets/javascripts/category.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/category.scss b/app/assets/stylesheets/category.scss new file mode 100644 index 0000000000..c8ae451b23 --- /dev/null +++ b/app/assets/stylesheets/category.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the category 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/category_controller.rb b/app/controllers/category_controller.rb new file mode 100644 index 0000000000..58cd7a1d87 --- /dev/null +++ b/app/controllers/category_controller.rb @@ -0,0 +1,8 @@ +class CategoryController < ApplicationController + def show + category_id = params[:id] + @category = Category.find_by(id: category_id) + @items_in_category = Item.where(active: true, category_id: category_id) + + end +end diff --git a/app/helpers/category_helper.rb b/app/helpers/category_helper.rb new file mode 100644 index 0000000000..ac5cb5bf58 --- /dev/null +++ b/app/helpers/category_helper.rb @@ -0,0 +1,2 @@ +module CategoryHelper +end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000000..54cb6aee3f --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,2 @@ +class Category < ApplicationRecord +end diff --git a/app/views/category/show.html.erb b/app/views/category/show.html.erb new file mode 100644 index 0000000000..a3f0cbf9fc --- /dev/null +++ b/app/views/category/show.html.erb @@ -0,0 +1,12 @@ +
+

+ <%= @category.category_type.capitalize %> +

+ + + <% @items_in_category.each do |item| %> +

+ <%= item.name %>: <%= item.description %> +

+ <% end %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f7061ec8d2..a12e4b5507 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -49,14 +49,12 @@ Categories + + <% if @current_user && @current_user.is_a_merchant?(@merchant_ids) %> - <% end %> + From 7ddc735c7fd0d326992ef1e5e47d2b9304ca658b Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 16:20:33 -0700 Subject: [PATCH 057/281] removed commented lines of code --- app/controllers/application_controller.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9913a3c5f7..607c0d3fb1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,6 @@ class ApplicationController < ActionController::Base before_action :find_current_user before_action :find_all_merchants - # before_action :is_a_merchant? before_action :current_order # before_action :require_login, except: :index @@ -24,10 +23,6 @@ def find_all_merchants end end - # def is_a_merchant? - # @merchant = @merchant_ids.include?(@current_user.id) - # end - def require_login unless @current_user flash[:failure] = "You must be logged in to do that." From 5bc57e4131f34d125cd4f8fe4a4d7e48a55cc809 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 16:41:52 -0700 Subject: [PATCH 058/281] wrapped find_item_category items_controlelr in conditional for nil category --- app/controllers/items_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 0b6dcf9155..48f6ced0a1 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -65,7 +65,8 @@ def find_searched_item end def find_item_category - find_searched_item - @item_category = Category.find(@item.category_id).category_type + if @item.category_id + @item_category = Category.find(@item.category_id).category_type + end end end From 3168def0faf64f096ad6e46e28db7e7cd1885e3b Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 16:43:33 -0700 Subject: [PATCH 059/281] deleted if, bc category cant be nil --- app/controllers/items_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 48f6ced0a1..d8daac6673 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -65,8 +65,6 @@ def find_searched_item end def find_item_category - if @item.category_id @item_category = Category.find(@item.category_id).category_type - end end end From adf87eef7cb36b3195276513476898771de214fd Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sat, 20 Oct 2018 18:48:23 -0700 Subject: [PATCH 060/281] committing changes before pulling master --- app/controllers/items_controller.rb | 3 ++- app/models/category.rb | 1 + app/models/item.rb | 1 - db/user_seeds.csv | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index d8daac6673..a715021c28 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -65,6 +65,7 @@ def find_searched_item end def find_item_category - @item_category = Category.find(@item.category_id).category_type + @item = Item.find_by(id: params[:id]) + @item_category = Category.find(@item.category_id).category_type end end diff --git a/app/models/category.rb b/app/models/category.rb index 2951670359..617beb27c1 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,3 +1,4 @@ class Category < ApplicationRecord + has_many :items end diff --git a/app/models/item.rb b/app/models/item.rb index a67baf91cf..f95e70b7ad 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -2,6 +2,5 @@ class Item < ApplicationRecord belongs_to :user has_many :orderitems has_many :reviews - belongs_to :categories end diff --git a/db/user_seeds.csv b/db/user_seeds.csv index d127654ae7..1c722127f4 100644 --- a/db/user_seeds.csv +++ b/db/user_seeds.csv @@ -3,3 +3,4 @@ jen,jen_is_cool,jen@gmail.com,https://goo.gl/4usQGd,991,aim doug,doug-donut,doug@gmail.com,https://goo.gl/DBLsc9,992,aim jazz,jazzed,jazz@gmail.com,https://bit.ly/2R5zhBa,993,aim layla,layayala,laya@gmail.com,https://plbz.it/2pZTSeB,994,aim +guest, guest, guest@guest.com, none, 0000, github From 4dfe2470b9163af146e6c23feb7d0eded24d06ff Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Sat, 20 Oct 2018 18:50:29 -0700 Subject: [PATCH 061/281] Added a migration --- app/models/category.rb | 1 + app/models/item.rb | 2 +- db/migrate/20181021014223_delete_user_id_from_order.rb | 5 +++++ db/schema.rb | 5 +---- db/user_seeds.csv | 1 + 5 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20181021014223_delete_user_id_from_order.rb diff --git a/app/models/category.rb b/app/models/category.rb index 54cb6aee3f..7d27fd493c 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,2 +1,3 @@ class Category < ApplicationRecord + has_many :items end diff --git a/app/models/item.rb b/app/models/item.rb index f95e70b7ad..0ea7b45577 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -2,5 +2,5 @@ class Item < ApplicationRecord belongs_to :user has_many :orderitems has_many :reviews - + belongs_to :category end diff --git a/db/migrate/20181021014223_delete_user_id_from_order.rb b/db/migrate/20181021014223_delete_user_id_from_order.rb new file mode 100644 index 0000000000..6b9fd6ba96 --- /dev/null +++ b/db/migrate/20181021014223_delete_user_id_from_order.rb @@ -0,0 +1,5 @@ +class DeleteUserIdFromOrder < ActiveRecord::Migration[5.2] + def change + remove_column :orders, :user_id + end +end diff --git a/db/schema.rb b/db/schema.rb index c57a08577a..cf1bfe7771 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_20_161500) do +ActiveRecord::Schema.define(version: 2018_10_21_014223) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -61,8 +61,6 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "status", default: "pending" - t.bigint "user_id" - t.index ["user_id"], name: "index_orders_on_user_id" end create_table "reviews", force: :cascade do |t| @@ -91,7 +89,6 @@ add_foreign_key "items", "users" add_foreign_key "order_items", "items" add_foreign_key "order_items", "orders" - add_foreign_key "orders", "users" add_foreign_key "reviews", "items" add_foreign_key "reviews", "users" end diff --git a/db/user_seeds.csv b/db/user_seeds.csv index d127654ae7..2956dc0653 100644 --- a/db/user_seeds.csv +++ b/db/user_seeds.csv @@ -3,3 +3,4 @@ jen,jen_is_cool,jen@gmail.com,https://goo.gl/4usQGd,991,aim doug,doug-donut,doug@gmail.com,https://goo.gl/DBLsc9,992,aim jazz,jazzed,jazz@gmail.com,https://bit.ly/2R5zhBa,993,aim layla,layayala,laya@gmail.com,https://plbz.it/2pZTSeB,994,aim +guest, guest, guest@guest.com, none, 0, github From 3479eeeb13cffed6889d877df94c9bdaa941ed88 Mon Sep 17 00:00:00 2001 From: Kat Perreira Date: Sat, 20 Oct 2018 18:50:33 -0700 Subject: [PATCH 062/281] added form partial, new and edit to items --- app/views/items/_item_form.html.erb | 33 +++++++++++++++++++++++++++++ app/views/items/edit.html.erb | 8 +++++++ app/views/items/new.html.erb | 7 ++++++ 3 files changed, 48 insertions(+) create mode 100644 app/views/items/_item_form.html.erb create mode 100644 app/views/items/edit.html.erb create mode 100644 app/views/items/new.html.erb diff --git a/app/views/items/_item_form.html.erb b/app/views/items/_item_form.html.erb new file mode 100644 index 0000000000..7f0db3c527 --- /dev/null +++ b/app/views/items/_item_form.html.erb @@ -0,0 +1,33 @@ +<%= render partial: 'layouts/form_errors', +locals: { + model: @item +} +%> + +:name, +:price, +:quantity_available, +:description, +:image, +:active + +<%= form_with model: @item, class: 'item-form' do |f| %> + + <%= f.label :Name %> + <%= f.text_field :name %> + <%= f.label :price %> + <%= f.text_field :price %> + <%= f.label :quantity_available %> + <%= f.text_field :quantity_available %> + <%= f.label :image %> + <%= f.text_field :image %> + <%= f.label :active %> + <%= f.text_field :active %> + <%= f.label :description %> + <%= f.text_area :description %> + + + + <%= f.submit action_type, class: "item-form-submit-button" %> + +<% end %> diff --git a/app/views/items/edit.html.erb b/app/views/items/edit.html.erb new file mode 100644 index 0000000000..3f838a70ce --- /dev/null +++ b/app/views/items/edit.html.erb @@ -0,0 +1,8 @@ +

Edit Your Product

+ + +<%= render partial: "item_form", locals: { + action_type: "Submit Changes", + form_title: "Submit Changes" + } +%> diff --git a/app/views/items/new.html.erb b/app/views/items/new.html.erb new file mode 100644 index 0000000000..aa3594565b --- /dev/null +++ b/app/views/items/new.html.erb @@ -0,0 +1,7 @@ +

Add a New Product

+ +<%= render partial: 'item_form', locals: { + action_type: "Submit", + form_title: "New!" + } +%> From f199db64614236a6c67ba73fe1d04f2889e08aa4 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 20:08:12 -0700 Subject: [PATCH 063/281] changed name of flash message to match the ones my partners were using --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 607c0d3fb1..dada2dce02 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -25,7 +25,7 @@ def find_all_merchants def require_login unless @current_user - flash[:failure] = "You must be logged in to do that." + flash[:error] = "You must be logged in to do that." redirect_to root_path end end From 98c6af94fadf0e2a19ead2d50e22818cc72d67c2 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 20:11:21 -0700 Subject: [PATCH 064/281] added css styling to flash --- app/assets/stylesheets/application.scss | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index a90251dbf3..9ae5fff5f0 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -34,3 +34,23 @@ // border-bottom: .25px solid lightgrey; background-color: blue; } + +section .success, section .form_errors, section .failure { + text-align: center; + padding: 0.75rem 1.25rem; + margin: 1em; + border: 1px solid transparent; + border-radius: 0.25rem; +} + +section .success { + color: #155724; + background-color: #d4edda; + border-color: #c3e6cb; +} + +section .failure, section .form_errors{ + color: #856404; + background-color: #fff3cd; + border-color: #ffeeba; +} From 319f1983e5b77c8bf60615b889a895a0802a19e6 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sat, 20 Oct 2018 20:13:08 -0700 Subject: [PATCH 065/281] created relations between order and order_item --- app/models/order.rb | 2 +- app/models/order_item.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/order.rb b/app/models/order.rb index 84009764a6..37a41f1574 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,4 +1,4 @@ class Order < ApplicationRecord belongs_to :user - has_many :orderitems + has_many :order_items end diff --git a/app/models/order_item.rb b/app/models/order_item.rb index acc6099fd0..86207afe6f 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,2 +1,3 @@ class OrderItem < ApplicationRecord + belongs_to :order end From 1e4d9d29d96c08bb9d6df2923f6770c198dceaa1 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 20:32:13 -0700 Subject: [PATCH 066/281] changed application controller to connect user show page to dropdown merchant view --- app/views/layouts/application.html.erb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index eb782ca990..8113934980 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -64,8 +64,7 @@ From e7e2be23d96f9e959b4f21c570fe2940e8185c05 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 20:53:12 -0700 Subject: [PATCH 067/281] added logic for nav/login uservs merchant vs guest view --- app/controllers/application_controller.rb | 3 +++ app/controllers/users_controller.rb | 3 ++- app/views/layouts/application.html.erb | 22 +++++++++++++++------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dada2dce02..1258b6b6a4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,6 +10,9 @@ class ApplicationController < ActionController::Base def find_current_user @current_user = User.find_by(id: session[:user_id]) + # else + # @guest_user = #allocated guest or User.find_by() + # end end #find all merchants diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f10c0c32b1..3e6ee5ad57 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,12 +3,13 @@ class UsersController < ApplicationController before_action :find_searched_user, only: [:show] before_action :find_current_user_items, only: [:shop] - #PROFILE + #user profile / merchant page that is visible to all def show head :not_found unless @user # render 'layouts/invalid_page', status: :not_found end + #merchant view that is visible to just merchants def shop redirect_to root_path unless @current_user end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index eb782ca990..900360d014 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,14 +14,22 @@
    - <% if session[:user_id] %> - <% current_user = User.find_by(id: session[:user_id]) %> -
  • - Welcome, <%= current_user.nickname %> -

  • - <% end %> + + <% if @current_user.nil? || !@current_user.is_a_merchant?(@merchant_ids)%> +
  • + <%= link_to "Become a Merchant", shop_path %> +
  • + <%else%> +
  • + <%= link_to "Manage Shop", shop_path %> +
  • + <%end%> - <% if session[:user_id] %> + + <% if @current_user %> +
  • + Welcome, <%= @current_user.nickname %> +

  • <%= link_to "Log Out", logout_path, method: :post %>
  • From 158ea5cdca38343d58f14b9f3a02d4fcc6455f01 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 21:12:54 -0700 Subject: [PATCH 068/281] refactored user#shop stuff --- app/controllers/users_controller.rb | 5 ++- app/views/layouts/application.html.erb | 12 ++++-- app/views/users/shop.html.erb | 53 +++++++++++++++----------- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3e6ee5ad57..07620c59bc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -11,7 +11,10 @@ def show #merchant view that is visible to just merchants def shop - redirect_to root_path unless @current_user + unless @current_user + flash[:error] = "You need to sign up to create a shop." + redirect_to root_path + end end private diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 900360d014..7d9a96eda8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,8 +14,8 @@
      - - <% if @current_user.nil? || !@current_user.is_a_merchant?(@merchant_ids)%> + + <% if @current_user && !@current_user.is_a_merchant?(@merchant_ids)%>
    • <%= link_to "Become a Merchant", shop_path %>
    • @@ -25,7 +25,7 @@ <%end%> - + <% if @current_user %>
    • Welcome, <%= @current_user.nickname %> @@ -84,6 +84,12 @@

+
+ <% flash.each do |key_word, message| %> +
<%=message%>
+ <% end %> +
+ <%= yield %>
diff --git a/app/views/users/shop.html.erb b/app/views/users/shop.html.erb index 248d741d4b..91a8cf50ff 100644 --- a/app/views/users/shop.html.erb +++ b/app/views/users/shop.html.erb @@ -1,28 +1,37 @@
-<%= image_tag "#{@current_user.image_url}", alt: "user image", title: "#{@current_user.name}'s profile pic", style: 'float:right;'%> -
    -
  • Id: <%= @current_user.id %>
  • -
  • Name: <%= @current_user.name %>
  • -
  • Username: <%= @current_user.nickname %>
  • -
  • Contact: <%= @current_user.email %>
  • -
- -
-

<%=@current_user.name%>'s Shop

-
-
    -
  • <%=link_to "Add New Product", new_item_path%>
  • -
+
+ <%= image_tag "#{@current_user.image_url}", alt: "user image", title: "#{@current_user.name}'s profile pic", style: 'float:right;'%>
    - <%@current_user_items.each do |item| %> -
  • For sale: <%=item.name%><%= link_to "(details)", item_path(item)%><%= link_to "(edit)", edit_item_path(item)%>
  • -
  • Stock: <%=item.quantity_available%>
  • -
  • Price: $<%=item.price%>
  • -
  • Category: <%=item.category_id%>
  • - <%end%> +
  • Id: <%= @current_user.id %>
  • +
  • Name: <%= @current_user.name %>
  • +
  • Username: <%= @current_user.nickname %>
  • +
  • Contact: <%= @current_user.email %>
-
-
+ + + <%if @current_user.is_a_merchant?(@merchant_ids)%> +
+

<%=@current_user.name%>'s Shop

+
+
    +
  • <%=link_to "Add New Product", new_item_path%>
  • +
+
    + <%@current_user_items.each do |item| %> +
  • For sale: <%=item.name%><%= link_to "(details)", item_path(item)%><%= link_to "(edit)", edit_item_path(item)%>
  • +
  • Stock: <%=item.quantity_available%>
  • +
  • Price: $<%=item.price%>
  • +
  • Category: <%=item.category_id%>
  • + <% end %> +
+
+
+ <%else%> +
+

Create your first product in your shop!

+

<%= link_to "Add Product", new_item_path %>

+
+ <%end%>
From d8b38699b5f4e2dfe4e45570d68442f7a24c79dc Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 21:14:11 -0700 Subject: [PATCH 069/281] changed names on styling ot match partner names --- app/assets/stylesheets/application.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 9ae5fff5f0..cb60403c8d 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -35,7 +35,7 @@ background-color: blue; } -section .success, section .form_errors, section .failure { +section .success, section .form_errors, section .error { text-align: center; padding: 0.75rem 1.25rem; margin: 1em; @@ -49,7 +49,7 @@ section .success { border-color: #c3e6cb; } -section .failure, section .form_errors{ +section .error, section .form_errors{ color: #856404; background-color: #fff3cd; border-color: #ffeeba; From dc287bb195ef006c060b9180359bb236b4069b1b Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sat, 20 Oct 2018 21:23:41 -0700 Subject: [PATCH 070/281] added delete button to user view --- app/views/users/shop.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/shop.html.erb b/app/views/users/shop.html.erb index 91a8cf50ff..59ada177a9 100644 --- a/app/views/users/shop.html.erb +++ b/app/views/users/shop.html.erb @@ -19,7 +19,7 @@
    <%@current_user_items.each do |item| %> -
  • For sale: <%=item.name%><%= link_to "(details)", item_path(item)%><%= link_to "(edit)", edit_item_path(item)%>
  • +
  • For sale: <%=item.name%><%= link_to "(details)", item_path(item)%><%= link_to "(edit)", edit_item_path(item)%><%= link_to "(delete)", item_path(item), method: :delete, data: { confirm: "Are you sure you want to delete this product: #{item.name}? You have #{item.quantity_available} of them"} %>
  • Stock: <%=item.quantity_available%>
  • Price: $<%=item.price%>
  • Category: <%=item.category_id%>
  • From b290cb0e2b292a000a13b4280f35c1e4b247a64d Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sat, 20 Oct 2018 22:24:17 -0700 Subject: [PATCH 071/281] added logic to add items to an order --- app/controllers/application_controller.rb | 6 +-- app/controllers/order_items_controller.rb | 46 ++++++++++++++++++++++ app/controllers/orderitems_controller.rb | 47 ----------------------- app/controllers/orders_controller.rb | 3 +- app/models/item.rb | 2 +- app/models/order.rb | 2 +- app/models/user.rb | 2 +- app/views/items/show.html.erb | 4 +- app/views/orders/show.html.erb | 6 ++- config/routes.rb | 6 ++- 10 files changed, 66 insertions(+), 58 deletions(-) create mode 100644 app/controllers/order_items_controller.rb delete mode 100644 app/controllers/orderitems_controller.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 607c0d3fb1..5be8ae9bac 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base before_action :find_current_user before_action :find_all_merchants - before_action :current_order + helper_method :current_order # before_action :require_login, except: :index private @@ -32,9 +32,9 @@ def require_login def current_order if session[:order_id] - @order = Order.find(session[:order_id]) + Order.find(session[:order_id]) else - @order = Order.new + Order.new end end end diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb new file mode 100644 index 0000000000..d841f9c830 --- /dev/null +++ b/app/controllers/order_items_controller.rb @@ -0,0 +1,46 @@ +class OrderItemsController < ApplicationController + + def create + + @order = current_order + @item = Item.find_by(id: params[:item_id]) + + + @order_item = @order.order_items.new(item_id: @item.id) + + if @order.save + session[:order_id] = @order.id + redirect_to order_path(@order.id) + end + + end + + + # def show + # #show page for shopping cart that hasn't been submitted + # end + # + # + # + # + # + # def update + # @order_item = @order.order_items.find(params[:id]) + # @order_item.update_attributes(order_item_params) + # @order_items = @order.order_items + # end + # + # + # def destroy + # @order_item = @order.order_items.find(params[:id]) + # @order_item.destroy + # @order_items = @order.order_items + # end + + + private + def order_item_params + params.require(:order_item).permit(:shipped, :order_id, :item_id, :quantity_per_item) + end + +end diff --git a/app/controllers/orderitems_controller.rb b/app/controllers/orderitems_controller.rb deleted file mode 100644 index 9d7fa15e7f..0000000000 --- a/app/controllers/orderitems_controller.rb +++ /dev/null @@ -1,47 +0,0 @@ -class OrderitemsController < ApplicationController - - def create - - - if session[:order_id] - @order = Order.find(session[:order_id]) - else - @order = Order.new - end - - - - @order_item = @order.order_items.new(order_item_params) - @order.save - - end - - - def show - #show page for shopping cart that hasn't been submitted - end - - - - - - def update - @order_item = @order.order_items.find(params[:id]) - @order_item.update_attributes(order_item_params) - @order_items = @order.order_items - end - - - def destroy - @order_item = @order.order_items.find(params[:id]) - @order_item.destroy - @order_items = @order.order_items - end - - - private - def order_item_params - params.require(:order_item).permit(:shipped, :order_id, :item_id, :quantity_per_item) - end - -end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 09e7ac5801..4feda78b1c 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,6 +1,7 @@ class OrdersController < ApplicationController def show - + @order = current_order + @order_items = current_order.order_items end end diff --git a/app/models/item.rb b/app/models/item.rb index 0ea7b45577..61fb59763b 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -1,6 +1,6 @@ class Item < ApplicationRecord belongs_to :user - has_many :orderitems + has_many :order_items has_many :reviews belongs_to :category end diff --git a/app/models/order.rb b/app/models/order.rb index 37a41f1574..742af690d5 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,4 +1,4 @@ class Order < ApplicationRecord - belongs_to :user + # belongs_to :user has_many :order_items end diff --git a/app/models/user.rb b/app/models/user.rb index a440d82f14..bbab1bed40 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ApplicationRecord has_many :items - has_many :orders + # has_many :orders has_many :reviews # def self.build_from_github(auth_hash) diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 0754b9bce3..ee2fa94aae 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -6,4 +6,6 @@ Price: <%= @item.price.to_f %>
    <%= @item.avg_rating %> <%= @item.description %> -<%= link_to "test", method: :post %> +Order: <%= @order %> + +<%= link_to "Add to Cart", item_order_items_path(@item.id), method: :post %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 88981c3196..ed6f104410 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,3 +1,5 @@ -order: <% @order_items.each do |item| %> -<%= item.name %> +<% @order_items.each do |item| %> + +Order Item: <%= item.id %> +
    <% end %> diff --git a/config/routes.rb b/config/routes.rb index f5f80325ee..592668e045 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,11 @@ root 'homepage#index' resources :users, only: [:show, :shop, :orders] - resources :orders, :orderitems, :items, :reviews, :category + resources :orders, :items, :reviews, :category + + resources :items do + resources :order_items, only: [:create] + end get "/auth/:provider/callback", to: "sessions#create" post '/logout', to: 'sessions#logout', as: 'logout' From 6d8e2cdd2bf1c9be720d1f8e3d72b25d271809ab Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sat, 20 Oct 2018 22:43:03 -0700 Subject: [PATCH 072/281] added validation for item_id to order --- app/controllers/order_items_controller.rb | 2 +- app/models/order_item.rb | 3 +++ app/views/orders/show.html.erb | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index d841f9c830..5a5eeceb54 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -8,7 +8,7 @@ def create @order_item = @order.order_items.new(item_id: @item.id) - if @order.save + if @order_item.save session[:order_id] = @order.id redirect_to order_path(@order.id) end diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 86207afe6f..5c94974ac7 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,3 +1,6 @@ class OrderItem < ApplicationRecord belongs_to :order + + validates :item_id, presence: true + end diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index ed6f104410..75607aa77b 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,5 +1,6 @@ <% @order_items.each do |item| %> - +<% x = Item.find_by(id: item.id) %> +<%= x.name %> Order Item: <%= item.id %>
    <% end %> From eceba22280ef4728acdd0370424e4fa4024a9157 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sat, 20 Oct 2018 22:50:16 -0700 Subject: [PATCH 073/281] fixed show view for order --- app/views/orders/show.html.erb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 75607aa77b..bace9dee2d 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,6 +1,5 @@ <% @order_items.each do |item| %> -<% x = Item.find_by(id: item.id) %> +<% x = Item.find_by(id: item.item_id) %> <%= x.name %> -Order Item: <%= item.id %>
    <% end %> From 9974d9a2fb1100b5e46d0319e73e99800834dd8f Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sun, 21 Oct 2018 08:59:50 -0700 Subject: [PATCH 074/281] added quantity field to order_item --- app/controllers/order_items_controller.rb | 2 +- app/views/items/_form.html.erb | 22 ++++++++++++++++++++++ app/views/items/show.html.erb | 4 +--- app/views/orders/show.html.erb | 4 +++- 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 app/views/items/_form.html.erb diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index 5a5eeceb54..cfd8d9c68d 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -6,7 +6,7 @@ def create @item = Item.find_by(id: params[:item_id]) - @order_item = @order.order_items.new(item_id: @item.id) + @order_item = @order.order_items.new(item_id: @item.id, quantity_per_item: params[:quantity_per_item]) if @order_item.save session[:order_id] = @order.id diff --git a/app/views/items/_form.html.erb b/app/views/items/_form.html.erb new file mode 100644 index 0000000000..d3c29c4ebe --- /dev/null +++ b/app/views/items/_form.html.erb @@ -0,0 +1,22 @@ +<%= form_with model: @order_item, :url => item_order_items_path(@item.id) do |f| %> + +<%= f.label :quantity_per_item %>
    +<%= f.text_field :quantity_per_item %> + + +<%= f.submit action_name %> +<% end %> + + + + + + diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index ee2fa94aae..22550b7b2c 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -6,6 +6,4 @@ Price: <%= @item.price.to_f %>
    <%= @item.avg_rating %> <%= @item.description %> -Order: <%= @order %> - -<%= link_to "Add to Cart", item_order_items_path(@item.id), method: :post %> +<%= render partial: "form", locals: { action_name: "Add to Cart"} %> diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index bace9dee2d..634a6c7d6c 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,5 +1,7 @@ <% @order_items.each do |item| %> <% x = Item.find_by(id: item.item_id) %> -<%= x.name %> +<%= x.name%> +<% y = item.quantity_per_item %> +Quantity: <%= y %>
    <% end %> From 916ca7fdadc73ed60a963c2b7f809a7fc0ada050 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sun, 21 Oct 2018 09:16:40 -0700 Subject: [PATCH 075/281] added delete functionality to order items --- app/controllers/order_items_controller.rb | 22 +++++++++------------- app/views/orders/show.html.erb | 4 ++-- config/routes.rb | 2 ++ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index cfd8d9c68d..ee0d6cdfe6 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -16,14 +16,7 @@ def create end - # def show - # #show page for shopping cart that hasn't been submitted - # end - # - # - # - # - # + # def update # @order_item = @order.order_items.find(params[:id]) # @order_item.update_attributes(order_item_params) @@ -31,11 +24,14 @@ def create # end # # - # def destroy - # @order_item = @order.order_items.find(params[:id]) - # @order_item.destroy - # @order_items = @order.order_items - # end + def destroy + @order = current_order + @order_item = @order.order_items.find(params[:id]) + @order_item.destroy + @order_items = @order.order_items + + redirect_to order_path + end private diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 634a6c7d6c..c196d5da6c 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,7 +1,7 @@ <% @order_items.each do |item| %> <% x = Item.find_by(id: item.item_id) %> <%= x.name%> -<% y = item.quantity_per_item %> -Quantity: <%= y %> +Quantity: <%= item.quantity_per_item %> +<%= link_to "Delete Item", order_item_path(item.id), method: :delete, data: { confirm: "are you sure you want to delete this item?" } %>
    <% end %> diff --git a/config/routes.rb b/config/routes.rb index 592668e045..3e92c76aac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,8 @@ resources :users, only: [:show, :shop, :orders] resources :orders, :items, :reviews, :category + resources :order_items, only: [:update, :destroy] + resources :items do resources :order_items, only: [:create] end From 03e76bb06ce53abf9d818b756f29c4033d69f971 Mon Sep 17 00:00:00 2001 From: Chantelle Belic Date: Sun, 21 Oct 2018 09:44:17 -0700 Subject: [PATCH 076/281] added to condition in application layout so guest users cant see anything related to managing merchnat shop or becoming a merchant --- app/controllers/items_controller.rb | 2 +- app/views/layouts/application.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index d8daac6673..5651e98c67 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -1,6 +1,6 @@ class ItemsController < ApplicationController + before_action :find_searched_item, only: [:show, :edit, :update, :destroy, :find_item_category,] before_action :find_item_category, only: [:show] - before_action :find_searched_item, only: [:show, :edit, :update, :destroy] def index @items = Item.all diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7d9a96eda8..912b5604cc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -19,7 +19,7 @@
  • <%= link_to "Become a Merchant", shop_path %>
  • - <%else%> + <%elsif @current_user && @current_user.is_a_merchant?(@merchant_ids)%>
  • <%= link_to "Manage Shop", shop_path %>
  • From c10941c155823f7172d65fc738206e38a07621a5 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sun, 21 Oct 2018 09:51:54 -0700 Subject: [PATCH 077/281] created update action for item order quantity --- app/controllers/order_items_controller.rb | 20 ++++++++++++-------- app/views/items/_form.html.erb | 2 +- app/views/items/show.html.erb | 2 +- app/views/orders/_form.html.erb | 22 ++++++++++++++++++++++ app/views/orders/show.html.erb | 19 +++++++++++++++++++ 5 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 app/views/orders/_form.html.erb diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index ee0d6cdfe6..d1218c1c2e 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -17,20 +17,24 @@ def create - # def update - # @order_item = @order.order_items.find(params[:id]) - # @order_item.update_attributes(order_item_params) - # @order_items = @order.order_items - # end - # - # + def update + @order = current_order + @order_item = @order.order_items.find(params[:id]) + + @order_item.update_attributes(quantity_per_item: params[:quantity_per_item]) + @order_items = @order.order_items + + redirect_to order_path(@order) + end + + def destroy @order = current_order @order_item = @order.order_items.find(params[:id]) @order_item.destroy @order_items = @order.order_items - redirect_to order_path + redirect_to order_path(@order) end diff --git a/app/views/items/_form.html.erb b/app/views/items/_form.html.erb index d3c29c4ebe..d1634b57fa 100644 --- a/app/views/items/_form.html.erb +++ b/app/views/items/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_with model: @order_item, :url => item_order_items_path(@item.id) do |f| %> +<%= form_with model: @order_item, method: requested_method, :url => item_order_items_path(@item.id) do |f| %> <%= f.label :quantity_per_item %>
    <%= f.text_field :quantity_per_item %> diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 22550b7b2c..114f173ad3 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -6,4 +6,4 @@ Price: <%= @item.price.to_f %>
    <%= @item.avg_rating %> <%= @item.description %> -<%= render partial: "form", locals: { action_name: "Add to Cart"} %> +<%= render partial: "form", locals: { action_name: "Add to Cart", requested_method: :post} %> diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb new file mode 100644 index 0000000000..d1634b57fa --- /dev/null +++ b/app/views/orders/_form.html.erb @@ -0,0 +1,22 @@ +<%= form_with model: @order_item, method: requested_method, :url => item_order_items_path(@item.id) do |f| %> + +<%= f.label :quantity_per_item %>
    +<%= f.text_field :quantity_per_item %> + + +<%= f.submit action_name %> +<% end %> + + + + + + diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index c196d5da6c..9794a51cab 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -2,6 +2,25 @@ <% x = Item.find_by(id: item.item_id) %> <%= x.name%> Quantity: <%= item.quantity_per_item %> + +
    + +TEST: + + +<%= form_with model: @order_item, method: :patch, :url => order_item_path(item.id) do |f| %> + +<%= f.label :quantity_per_item %>
    +<%= f.text_field :quantity_per_item %> + + +<%= f.submit action_name %> +<% end %> + + + + <%= link_to "Delete Item", order_item_path(item.id), method: :delete, data: { confirm: "are you sure you want to delete this item?" } %> +
    <% end %> From a49196945eacd3028f35444eb164716331fe5e80 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sun, 21 Oct 2018 12:44:06 -0700 Subject: [PATCH 078/281] fixed a few things to update and delete order_items --- app/controllers/application_controller.rb | 3 ++- app/controllers/items_controller.rb | 1 + app/controllers/order_items_controller.rb | 7 +++---- app/controllers/orders_controller.rb | 1 - app/models/order.rb | 2 ++ app/models/order_item.rb | 5 ++++- app/views/items/_form.html.erb | 22 ---------------------- app/views/items/show.html.erb | 18 ++++++++++++++---- app/views/layouts/application.html.erb | 2 ++ app/views/orders/_form.html.erb | 22 ---------------------- app/views/orders/show.html.erb | 15 ++++++--------- 11 files changed, 34 insertions(+), 64 deletions(-) delete mode 100644 app/views/items/_form.html.erb delete mode 100644 app/views/orders/_form.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5be8ae9bac..f49ec273c1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base before_action :find_current_user before_action :find_all_merchants - helper_method :current_order + before_action :current_order # before_action :require_login, except: :index private @@ -35,6 +35,7 @@ def current_order Order.find(session[:order_id]) else Order.new + end end end diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index a715021c28..1e1a695fd9 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -38,6 +38,7 @@ def create def show head :not_found unless @item + @order = current_order end def update diff --git a/app/controllers/order_items_controller.rb b/app/controllers/order_items_controller.rb index d1218c1c2e..1191867f44 100644 --- a/app/controllers/order_items_controller.rb +++ b/app/controllers/order_items_controller.rb @@ -19,10 +19,10 @@ def create def update @order = current_order - @order_item = @order.order_items.find(params[:id]) + @order_item = @order.order_items.find_by(id: params[:id]) + + @order_item.update(quantity_per_item: params[:quantity_per_item]) - @order_item.update_attributes(quantity_per_item: params[:quantity_per_item]) - @order_items = @order.order_items redirect_to order_path(@order) end @@ -32,7 +32,6 @@ def destroy @order = current_order @order_item = @order.order_items.find(params[:id]) @order_item.destroy - @order_items = @order.order_items redirect_to order_path(@order) end diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 4feda78b1c..3bb1db692b 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -1,7 +1,6 @@ class OrdersController < ApplicationController def show - @order = current_order @order_items = current_order.order_items end end diff --git a/app/models/order.rb b/app/models/order.rb index 742af690d5..15c07c3703 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,4 +1,6 @@ class Order < ApplicationRecord # belongs_to :user has_many :order_items + + end diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 5c94974ac7..ca1d1a3279 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,6 +1,9 @@ class OrderItem < ApplicationRecord belongs_to :order - validates :item_id, presence: true + def self.update_quantity + + end + end diff --git a/app/views/items/_form.html.erb b/app/views/items/_form.html.erb deleted file mode 100644 index d1634b57fa..0000000000 --- a/app/views/items/_form.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -<%= form_with model: @order_item, method: requested_method, :url => item_order_items_path(@item.id) do |f| %> - -<%= f.label :quantity_per_item %>
    -<%= f.text_field :quantity_per_item %> - - -<%= f.submit action_name %> -<% end %> - - - - - - diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 114f173ad3..9b7b4a00b2 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -1,9 +1,19 @@

    Product Details

    +<%= @item.image %>
    + Item name: <%= @item.name %>
    Category: <%= @item_category %>
    Price: <%= @item.price.to_f %>
    -<%= @item.image %> -<%= @item.avg_rating %> -<%= @item.description %> +Rating: <%= @item.avg_rating %>
    +Description:<%= @item.description %>
    + + + + <%= form_with model: @order_item, method: :post, :url => item_order_items_path(@item.id) do |f| %> + + <%= f.label "Quantity:" %> + <%= f.text_field :quantity_per_item %> + -<%= render partial: "form", locals: { action_name: "Add to Cart", requested_method: :post} %> + <%= f.submit "Add to Cart" %> + <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index eb782ca990..b3bd313a29 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -30,6 +30,8 @@ <%= link_to "Log In", "/auth/github" %> <% end %> + +
diff --git a/app/views/orders/_form.html.erb b/app/views/orders/_form.html.erb deleted file mode 100644 index d1634b57fa..0000000000 --- a/app/views/orders/_form.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -<%= form_with model: @order_item, method: requested_method, :url => item_order_items_path(@item.id) do |f| %> - -<%= f.label :quantity_per_item %>
-<%= f.text_field :quantity_per_item %> - - -<%= f.submit action_name %> -<% end %> - - - - - - diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index 9794a51cab..715023e7f6 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,26 +1,23 @@ -<% @order_items.each do |item| %> -<% x = Item.find_by(id: item.item_id) %> +<% @order_items.order('created_at').each do |item| %> +Item:<% x = Item.find_by(id: item.item_id) %> <%= x.name%> +
Quantity: <%= item.quantity_per_item %>
-TEST: - <%= form_with model: @order_item, method: :patch, :url => order_item_path(item.id) do |f| %> -<%= f.label :quantity_per_item %>
<%= f.text_field :quantity_per_item %> -<%= f.submit action_name %> +<%= f.submit "update quantity" %> <% end %> - - - <%= link_to "Delete Item", order_item_path(item.id), method: :delete, data: { confirm: "are you sure you want to delete this item?" } %> +
+

<% end %> From 0ed810b71851bd122b91a719da6f9796ed4e3983 Mon Sep 17 00:00:00 2001 From: Lindsay Terchin Date: Sun, 21 Oct 2018 13:34:47 -0700 Subject: [PATCH 079/281] got rid of order_item fields from show view --- app/models/order_item.rb | 3 --- app/views/items/show.html.erb | 1 - 2 files changed, 4 deletions(-) diff --git a/app/models/order_item.rb b/app/models/order_item.rb index ca1d1a3279..49d446d03a 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -2,8 +2,5 @@ class OrderItem < ApplicationRecord belongs_to :order validates :item_id, presence: true - def self.update_quantity - - end end diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 9b7b4a00b2..1f0d970c55 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -8,7 +8,6 @@ Rating: <%= @item.avg_rating %>
Description:<%= @item.description %>
- <%= form_with model: @order_item, method: :post, :url => item_order_items_path(@item.id) do |f| %> <%= f.label "Quantity:" %> From e0a076abec48ecf613e3337ba6968916e903992a Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Sun, 21 Oct 2018 13:36:53 -0700 Subject: [PATCH 080/281] Convert shopping cart icon to link --- .DS_Store | Bin 0 -> 8196 bytes app/.DS_Store | Bin 0 -> 8196 bytes app/assets/.DS_Store | Bin 0 -> 8196 bytes app/assets/images/.DS_Store | Bin 0 -> 8196 bytes app/views/category/show.html.erb | 2 ++ app/views/layouts/application.html.erb | 5 ++++- db/seeds.rb | 1 + 7 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 app/.DS_Store create mode 100644 app/assets/.DS_Store create mode 100644 app/assets/images/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..38e2e918f536a544ede3a8dd9ee07ed232dd7471 GIT binary patch literal 8196 zcmeHMO>h)N6n-xWWI7NsiGl187FJT>CkB#`ge1z(CL3ZxKqxmMKLj_kJ3}(%WM^%Yy|}dBTGi)Pt5{m3W9HSmi-49xW}c@?`mXdNx8ru4=(_RrlB3 zuix~%ufN%@?gaqs$!aYCApnplbClOm@qonbJTFT{eoqM@l0P`Y;@2O zFc2^hFc2^hFc2{Ce_(+2Y@VbQ_I+Uu%7B4@fk%=7{`(N2%rWZYyg=`#g9`5mK*)~( zUZT3pD})grqdv|HBnu@Ju7tuB{UZhncj}M$w4IN;s+)Cs z)XYiVIKZw{S9NtKAy+sQ=RnG~ zj%V~7#Wa$#&FqXtmdccBrm{3x?>5c2ab9;uUHz=fYvYccabw=VQGRd; zVO!1#J>w8Ec75&o@YZclG`Bx_AhuAxu0pP?Vr-oFuw3J`p=XBkhUQL>sZL6_G{c%2 z$r+B3H1#1%ozW|?k+FphHKB54qq3=BTIwRnb<$`yX`IO#?m2Ic&07>Uq0yTkwKYDA zCVwa~&r-KVQBHD8ETdDYNz#J6uA-dnP#T!5N<$7sB6@bQCMG*<=y_U9uSeO#+9X+H z!={?lP0`iCx+Hm!jpRhQqO*$am)K~^o|&N_9dFu$QAK%l)kSxRmG(HOi#Cgv%(oE*8sPx+!8oMAf;_wi7vU0If%o78xB)le zbNC9rhTHHB+=U(;xib> z2|R@foW#>;V;VE);4EIiSMXJQ9pA+F@hV=!>v#ii;>Y+2eu}s7Hr^5MS5(mH5z#J` z_&wG9&yaNLU!xU`JxHhFLw!%j{u7DU)tT*4(Qcdvdt!3afo zN+~G8Te|xs$Yrc-tYzV05|n;+sfY{WmP@(lr3HnQ5srknN~9CnZ`OymOQdAE$a~h# zhA@+hNwnS&BVR;qlQ}V2>ZH&n!Bw%6f>>}%GlB#$Vt7Qkt4&F4ZJ{)6`j4KIm zMcKUz*We@g3~rI!zJ(v)C-?>aB&n6)I+9ulYjG2XaT{*Oo!Eel*p7RB(e+{<_TvBv zFOI`Ff}=QwNz_PoQ#g%hNOoDwVIJr4C489#co8p=0N=pN_%^;HgtaKQ{({g1;#ERl zZn=2IGHq*$dJ5vae{j%xSQ#i5fra?_|Io_!{|{^UL0ka?0RzMUmh{GZdw699I`~;T zLV1!hPkh|GK+lDW`z`{gz4(VA)gv^N`$T=57f3yn{`HH1VE>0;|M#T#NEd$tmK4&9 literal 0 HcmV?d00001 diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d856c4d19c2f310c58a5c4ca2e25757a0be0fd2f GIT binary patch literal 8196 zcmeHMPiz!b82`Rf%Dh79fIxSEg_WlKsS9msp`iTPb_=!?gt#qjp}5TM4DH0}Oxc;; z1!~P|)RSQ3qa_bY+KJ9x6EQ%U6FJhU$-1HC!8(Aq#>h2mSecZZa423p14j* z8We>oEUiYSrrLM3#bfQeI;P{Xsm{*Uc&wv+=kzpF8k*Yn_MM(Me_`sm>F3{+abfUm zfclC!uT%zUdxfO@NKtjU9ORvHkc=(XdixIbr&TrYnNORx?pp=3NB2!Ht=4-KZC}=P zj^)e(MK+Xm?fis8mStJp&gN;b*=5@)>w@VG`{p^Hw@!F&&QFSg!xs7SzO=fW`yZY3 zE!Xjmn>mk=vFl4#MmKDHtaZoZ`;s$tOY7BT%NaXCtT?`P#xiq*Ma%HVM|3Z1I)>$p z4HYcU%GlrhmK z4cdCfv}IQ(+pVbmY^Wf^m7UAkUWE;3-H8bb(i79}PiWdReA>gh=O3Lk9a_@oGX@uLl41+I7X-sUE`z<(VOti`~mA_Inh{HZO2qz#54iw>4xCocv3cL&N!wt9z zpTU>#72Jle;V%3DKfy2XEBpq(!=JbaSKumazz9ByTX7q<;4a*aPv9Qx!b8}PNAM|3 z;V7QMG@iyY=;9>i(8DQw317xn@HKn`-@~hT4X@)3yon#-$M^}}!rOR9uCJ=B*2D6= zT;q4tnsZB%T7yq&RU`LPYxKauCzJn)TJJ8A5`ARF%5{yKw{Gv;lbGGeiv9b$iiB*W zE`(mndJr2pM~Ga^+UhkdI!LlI&s9pfEOB)am%cKikv^ia=mv$H?CkxKFfgEi9@oB$X<{+TOvKT1_&R)?K^FT0?@Bmtt$!ezJp@hBZZ#Oi^(@ z`OPc7ciEpm6n<}$Cbrv>Nk|)a6UsseP1B@JnzTvV6gGdfRVfMG{Iv~iylazKcG)&IG|n-h$A2&0iqIx0~Z7wxNzlw;El%{kxg^p0!Z;lo^L$w zJXk zraZupi3J!BuqeJ>7>_R%EH6rR(^q+04?Vk=kejZ5o2m3Hj0 ztikP5X~)WCY&Xej)0&meS(;}ISXRQkWVq9wvFP#EdDqE$L%!p*NwK^y$ym-c&KeY8 z=8a(ra~aAvw(W@C+uYi5u=iN}*7mzvJ(YU_vX)OZrZSQ)1I5k zo35F%jB#7b7`50g%YM|(234KTrOb;t(_3QAlH~U`HmS;tP9vRhbpAA*-IRoXtVvZb zaLZ8EpjrU7%4WN0aF(AR%lRiEU;KB~Fi=z?L>ls*f_9-t|m(2o8z6L zA=9a`3-;3)aS~=oy$i4eSKunV0I$P!cpq-UC-5nJ0bjyb@HKo7Kf+J&GyDR-!5{D^ z0wOB76B|&)`|v?*#l6^u-Pngm@fh~w2%g3>_!y4jG|plQ)2L$x^H{(|d=_8Cm+=*R z72m+O@f~~@-@^~^BQdQ=Nr)%KeW}KeskP?UMnVj}mPO9qNr=(m`jP)gh~I4!>btvs z$L{7m`#KLDeRy^E%C>Bcr2eiVUphh?zGh0A@WpzIG`cI=sN7SMaJjT6NM**N#6``j zg?B7^zeECIl7FkTL}i&IENm^&Hc4U;Vd;n-kV&(wLf8%}Jrb#tZ4uU9<%mrBWtGC( zuRJ7?Oj(t%HY$VkSolYJdlPQJhorS{;5Pg~I{TG0_B-jT8f$%hHDVL)#yzC5Hr$6D zco=)}2BAa10;E1dih*CIhV*XrqG{F^e9q;AJe5=AOeV_&i=E?Y)H8@U1en zoha!{AYLz5TRxGsEytdt{*pr1hJ<&UiGd2SSe57hBO8DJ-%ON*YYiFLbPQnSaAJ6n zmc7xTz;o>wU9)uY!u^T@{Sd1Bbezyn#|c;eVMy&5x$>BJfJK4SL*-xp5I}!)DB<}p N$oF?3tTrP9e*sQDy=?#h literal 0 HcmV?d00001 diff --git a/app/assets/images/.DS_Store b/app/assets/images/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..957b5e2ac3fd6b30b64aa17e22faaa01a344dd4e GIT binary patch literal 8196 zcmeHMO>h)N6n-xWWEu#WAdnrx!b%DVaRY$_k|;l$Y={XzLb(a~A-K%$3}nj5OxT&- z1!AmdsVBjblj23og9TK1!h;vogO*~Ic!(uf77769G<36t50yL<&I2Qvgw@ zPkDgwi3OMla9W~prF+Wk0RvYIQVf*tWRLObgoyyBB}#Wd=?)mIj6sHiVs-M1iRpj| ziD4Tu5HfH-1N`T+1Uwi67tDG2`&XF>+w%P8=I^nrykg1HN<~?wEUQ{}DmCU7Q@-x! zy)Hd>l3yLy{jp5Y?{{5$wy$SSSY|P;u1>m+uUn3p6V8@l(v;Cb%Q4(ymz#GCPuwRZ z4T{1PmR2K^lP$Y<#$zq*tyA&XWLsNvJl5K>XKIQmwVQYD>pMMu;o{^AQ!l%LVmyLI36(rUFwvG!$M z=XlO6P+Wsq*UpbSWU0yOb~aCw%}(1+Sr<)j$T!dXyf@;xIX@{T4q4>O$I|L5?tg5; zw_L|NVdgwS#%`=w6Wz4siRRr;?oZBCt*lmSRxvh0oH)L9#xipQMa%HVhIKD%I)>$( z9V}R$m9fo!M;|w9FwWS_+S*8!woY4LGA(pb)OuwopRvy6E&qa8W5Y&`jT-diM_q%j zVyGV}OjznSYT8L|N#;yy4MmwzS5{ZC2Cb2)y3+4aByyyQ?O>|M`k$u_6(ia%)~cum z8?g0^Y0IHD)}g3}*axCEEsD!dOL!cDjZ zU%=P!4cvim;U4@1zrb(sJNyBE!rxelt8p#XVgw(@CftrYupK+_Dcp;lcnA;UQG5nd zIEtq*ji>Ppx;TM3^l%bi!B_D$d;{OY5AYgZ#~XMPZ{a8SDSn2x@ebaV&sSE`>JfQe zYVil^&G|W!R)f!JWy25BYV=^w)5-rttM^t&fj+i+&4&7hrd@4&6SLd6VE5)~NQg$N zLa3#r2C;qfWXPqgt*c|v0TPvYexZ;{0#_@!@Rb>j)DewEHz}kQHMray-Kvn9)iQCf zZH-Z;mXmPBuSDCvgGJRPq)|m!TUr@YD@erB+TKCdr6gB*D^|x2kR8M_Y;!cp6crZ} z-=flc53a+<@HyNj$$bYu!q4z4{6%uBz?CGo2-e|xjN%sDircUecKo+Ihyv4BOK#+UGA65%DhOd@;}ui!iQt`yg- <%= item.name %>: <%= item.description %>

+ Shoes with bowties + <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index eb782ca990..33e5e3121d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,12 +7,16 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> +
    +
  • + +
  • <% if session[:user_id] %> <% current_user = User.find_by(id: session[:user_id]) %> @@ -69,7 +73,6 @@ <% end %> -
diff --git a/db/seeds.rb b/db/seeds.rb index 0d95709814..790d5a2746 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -46,3 +46,4 @@ end end ############################################################## +Item.create(name: "Bowsii MJ", description: "A delightfully fancy pair of shoes to wear to your next tea paaarte", price: 60, image: "https://cdn.shopify.com/s/files/1/0758/2735/products/TB1slR3JVXXXXbsXVXXXXXXXXXX__0-item_pic.jpg?v=1534937389", quantity_available: 10, user_id: 1, active: true, category_id: 6) From 04fcc6fef9b5e74198852664d2cb0c582979bca9 Mon Sep 17 00:00:00 2001 From: Kat Perreira Date: Sun, 21 Oct 2018 15:07:35 -0700 Subject: [PATCH 081/281] created seed data for items: luggage --- app/controllers/items_controller.rb | 2 +- app/views/items/index.html.erb | 5 ++++- app/views/layouts/_form_errors.html.erb | 15 +++++++++++++ db/item_seeds.csv | 5 +++++ db/seeds.rb | 29 ++++++++++++++++++++++++- 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 app/views/layouts/_form_errors.html.erb create mode 100644 db/item_seeds.csv diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index d8daac6673..5651e98c67 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -1,6 +1,6 @@ class ItemsController < ApplicationController + before_action :find_searched_item, only: [:show, :edit, :update, :destroy, :find_item_category,] before_action :find_item_category, only: [:show] - before_action :find_searched_item, only: [:show, :edit, :update, :destroy] def index @items = Item.all diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb index abb731250b..cb113aad07 100644 --- a/app/views/items/index.html.erb +++ b/app/views/items/index.html.erb @@ -6,12 +6,15 @@ <% @items.each do |item| %> - class="img-thumbnail, item_show" alt="cat_mask" > + class="img-thumbnail, item_show" > <%= item.name %> <%= item.price %> <%= item.quantity_available %> <%= item.avg_rating %> <%= item.description %> +
+
<% end %> + diff --git a/app/views/layouts/_form_errors.html.erb b/app/views/layouts/_form_errors.html.erb new file mode 100644 index 0000000000..4f9c141b70 --- /dev/null +++ b/app/views/layouts/_form_errors.html.erb @@ -0,0 +1,15 @@ +<% if model.errors.messages.any? %> +
+

There were some problems. Please fix them.

+
    + <% model.errors.messages.each do |field, problem_list| %> + <% problem_list.each do |problem| %> +
  • + <%= field %> + <%= problem %> +
  • + <% end %> + <% end %> +
+
+<% end %> diff --git a/db/item_seeds.csv b/db/item_seeds.csv new file mode 100644 index 0000000000..e9a3c6c341 --- /dev/null +++ b/db/item_seeds.csv @@ -0,0 +1,5 @@ +price,image,quantity_available,name,description,avg_rating,user_id,active,category_id +70,https://i.pinimg.com/236x/c3/62/9b/c3629b93a61797063ac2372ac7e63f29--liz-lisa-carry-bag.jpg,3,Sakura,20-inch hardside spinner luggage for weekend getaways or as international carry-on,4,7,true,5 +140,http://inhonorofdesign.com/wp-content/uploads/2015/01/Mint-Steamline-Luggage1.jpg,5,Steamline,Fully lined interior with divider; compression pad helps free up space; 150D-polyester interior organizer with 3 zippered pockets for securing smaller items,3,7,true,5 +100,https://rlv.zcache.com/custom_kawaii_cute_summer_tropical_pineapples_luggage-r086ff13689a94b06807ab730fe879e7e_64fbv_540.jpg?rlvnet=1,2,Globe Trotter,SMOOTH-ROLLING airflow multi-directional spinner wheels for easy movement,4,8,true,5 +30,https://i.ebayimg.com/images/g/wD0AAOSw5UVbaZD0/s-l640.jpg,5,Lets Go Pikachu Suitcase Cover,Now any boring suitcase can look amazing and bright thanks to this suitcase cover. The cover is stretchy so that it fits snug around your suitcase and it will keep your handles and wheels available for use so it just makes you suitcase look so much more fun.,4,8,true,5 diff --git a/db/seeds.rb b/db/seeds.rb index 0d95709814..5caabb0706 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -17,9 +17,12 @@ USER_FILE = Rails.root.join('db', 'user_seeds.csv') puts "Loading raw data from #{USER_FILE}" +ITEM_FILE = Rails.root.join('db', 'item_seeds.csv') +puts "Loading raw data from #{ITEM_FILE}" + ############################################################# #seeding categories -x = ["accessories", "books", "clothing", "horror", "luggage", "shoes", "tech", "miscellaneous"] +x = ["accessories", "books", "clothing", "seasonal", "luggage", "shoes", "tech", "miscellaneous"] x.each do |category| Category.create(category_type: category) end @@ -46,3 +49,27 @@ end end ############################################################## +#Seeding items + +item_failures = [] +CSV.foreach(ITEM_FILE, :headers => true) do |row| + + item = Item.new + item.price = row['price'] + item.image = row['image'] + item.quantity_available = row['quantity_available'] + item.name = row['name'] + item.description = row['description'] + item.avg_rating = row['provider'] + item.user_id = row['user_id'] + item.active = row['active'] + item.category_id = row['category_id'] + + successful = item.save + if !successful + item_failures << item + puts "Failed to save item: #{item.inspect}" + else + puts "Created item: #{item.inspect}" + end +end From 7e528651011cbb3ff8a3428e05356612446ca546 Mon Sep 17 00:00:00 2001 From: BarbaraWidjono Date: Sun, 21 Oct 2018 15:36:22 -0700 Subject: [PATCH 082/281] Homepage styling --- app/assets/stylesheets/application.scss | 35 ++++++++++++++++++++----- app/assets/stylesheets/homepage.scss | 3 +++ app/views/homepage/index.html.erb | 25 +++++++++++++++--- app/views/layouts/application.html.erb | 10 ++++++- db/item_seeds.csv | 11 ++++++++ db/seeds.rb | 18 ++++++++++++- 6 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 db/item_seeds.csv diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index a90251dbf3..11f10682b9 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -17,6 +17,24 @@ /* Import scss content */ @import "**/*"; +body{ + font-family: 'Quicksand', sans-serif; +} + +.top_of_page > ul >li{ + list-style-type: none; + float: right; + padding-right: 30px; +} + +header > h1{ + color: grey; + text-align: center; + font-family: 'Mali', cursive; + padding-top: 60px; + padding-bottom: 60px; + font-size: 3em; +} .navbar{ background-color: none; @@ -24,13 +42,16 @@ border-bottom: .25px solid lightgrey; } -.top_of_page > ul >li{ - list-style-type: none; - float: right; - padding-right: 30px; + + +footer{ + border-top: .25px solid lightgrey; + padding-left: 70px; + padding-right: 70px; + padding-top: 110px; + padding-bottom: 110px; } -.top_of_page{ - // border-bottom: .25px solid lightgrey; - background-color: blue; +li{ + list-style-type: none; } diff --git a/app/assets/stylesheets/homepage.scss b/app/assets/stylesheets/homepage.scss index 9027e07a04..7b42268b23 100644 --- a/app/assets/stylesheets/homepage.scss +++ b/app/assets/stylesheets/homepage.scss @@ -1,3 +1,6 @@ // Place all the styles related to the homepage controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ +.landing_page{ + padding: 110px; +} diff --git a/app/views/homepage/index.html.erb b/app/views/homepage/index.html.erb index 0eb10e9dcd..68cc94cb69 100644 --- a/app/views/homepage/index.html.erb +++ b/app/views/homepage/index.html.erb @@ -1,3 +1,22 @@ -
-

Welcome to Cute Stuff o-rama

-
+
+
+

Newest Arrivals

+
+ +
+
+ +
+

Featured Products

+
+ +
+
+ +
+

Staff Favorites

+
+ +
+
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 33e5e3121d..b65266794a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,6 +8,7 @@ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + @@ -37,7 +38,7 @@
-

Store Name

+

Kawaii Travel Shop