From 3cb47da59825d2dd7bb3180a18c18c83eccd89cb Mon Sep 17 00:00:00 2001 From: Kevin LeBlanc Date: Tue, 26 Jun 2018 13:45:13 -0400 Subject: [PATCH 1/5] First commit --- Gemfile.lock | 182 +++++++++++++++++++++++++++------------------------ 1 file changed, 95 insertions(+), 87 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c701ada1..0a81632e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,115 +1,123 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.0.1) - actionpack (= 5.0.0.1) - nio4r (~> 1.2) + actioncable (5.0.7) + actionpack (= 5.0.7) + nio4r (>= 1.2, < 3.0) websocket-driver (~> 0.6.1) - actionmailer (5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) + actionmailer (5.0.7) + actionpack (= 5.0.7) + actionview (= 5.0.7) + activejob (= 5.0.7) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.0.1) - actionview (= 5.0.0.1) - activesupport (= 5.0.0.1) + actionpack (5.0.7) + actionview (= 5.0.7) + activesupport (= 5.0.7) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.0.1) - activesupport (= 5.0.0.1) + actionview (5.0.7) + activesupport (= 5.0.7) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (5.0.0.1) - activesupport (= 5.0.0.1) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.0.7) + activesupport (= 5.0.7) globalid (>= 0.3.6) - activemodel (5.0.0.1) - activesupport (= 5.0.0.1) - activerecord (5.0.0.1) - activemodel (= 5.0.0.1) - activesupport (= 5.0.0.1) + activemodel (5.0.7) + activesupport (= 5.0.7) + activerecord (5.0.7) + activemodel (= 5.0.7) + activesupport (= 5.0.7) arel (~> 7.0) - activesupport (5.0.0.1) + activesupport (5.0.7) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) - binding_of_caller (0.7.2) + binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - builder (3.2.2) - byebug (9.0.6) + builder (3.2.3) + byebug (10.0.2) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.10.0) - concurrent-ruby (1.0.2) - debug_inspector (0.0.2) + coffee-script-source (1.12.2) + concurrent-ruby (1.0.5) + crass (1.0.4) + debug_inspector (0.0.3) erubis (2.7.0) execjs (2.7.0) - globalid (0.3.7) - activesupport (>= 4.1.0) - i18n (0.7.0) - jbuilder (2.6.0) - activesupport (>= 3.0.0, < 5.1) - multi_json (~> 1.2) - jquery-rails (4.2.1) + ffi (1.9.25) + globalid (0.4.1) + activesupport (>= 4.2.0) + i18n (1.0.1) + concurrent-ruby (~> 1.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) - json (1.8.3) - loofah (2.0.3) + json (1.8.6) + loofah (2.2.2) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.4) - mime-types (>= 1.16, < 4) - method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.9.1) - multi_json (1.12.1) - nio4r (1.2.1) - nokogiri (1.6.8.1) - mini_portile2 (~> 2.1.0) - rack (2.0.1) + mail (2.7.0) + mini_mime (>= 0.1.1) + method_source (0.9.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.11.3) + multi_json (1.13.1) + nio4r (2.3.1) + nokogiri (1.8.3) + mini_portile2 (~> 2.3.0) + rack (2.0.5) rack-test (0.6.3) rack (>= 1.0) - rails (5.0.0.1) - actioncable (= 5.0.0.1) - actionmailer (= 5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) - activemodel (= 5.0.0.1) - activerecord (= 5.0.0.1) - activesupport (= 5.0.0.1) - bundler (>= 1.3.0, < 2.0) - railties (= 5.0.0.1) + rails (5.0.7) + actioncable (= 5.0.7) + actionmailer (= 5.0.7) + actionpack (= 5.0.7) + actionview (= 5.0.7) + activejob (= 5.0.7) + activemodel (= 5.0.7) + activerecord (= 5.0.7) + activesupport (= 5.0.7) + bundler (>= 1.3.0) + railties (= 5.0.7) sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.1) - activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6.0) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.0.0.1) - actionpack (= 5.0.0.1) - activesupport (= 5.0.0.1) + 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.0.7) + actionpack (= 5.0.7) + activesupport (= 5.0.7) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (11.3.0) - rdoc (4.2.2) - json (~> 1.4) - sass (3.4.22) - sass-rails (5.0.6) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + rdoc (4.3.0) + sass (3.5.6) + 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) @@ -118,31 +126,31 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - spring (2.0.0) + spring (2.0.2) activesupport (>= 4.2) - sprockets (3.7.0) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.12) - thor (0.19.1) - thread_safe (0.3.5) - tilt (2.0.5) - tzinfo (1.2.2) + sqlite3 (1.3.13) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (3.0.3) + uglifier (4.1.12) execjs (>= 0.3.0, < 3) web-console (2.3.0) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) - websocket-driver (0.6.4) + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) + websocket-extensions (0.1.3) PLATFORMS ruby @@ -152,7 +160,7 @@ DEPENDENCIES coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails - rails (~> 5.0) + rails (~> 5.0.1) sass-rails (~> 5.0) sdoc (~> 0.4.0) spring @@ -161,4 +169,4 @@ DEPENDENCIES web-console (~> 2.0) BUNDLED WITH - 1.11.2 + 1.16.2 From 4079eeb1db79b3c5268ff83e56bb3202d40604d1 Mon Sep 17 00:00:00 2001 From: Kevin LeBlanc Date: Tue, 26 Jun 2018 14:10:20 -0400 Subject: [PATCH 2/5] Add Restaurant model, controller, routes. Add Restaurant Index page --- app/assets/javascripts/restaurants.coffee | 3 +++ app/assets/stylesheets/restaurants.scss | 3 +++ app/controllers/restaurants_controller.rb | 5 ++++ app/helpers/restaurants_helper.rb | 2 ++ app/models/restaurant.rb | 2 ++ app/views/restaurants/index.html.erb | 5 ++++ app/views/restaurants/show.html.erb | 0 config/routes.rb | 3 +++ .../20180626174750_create_restaurants.rb | 14 ++++++++++ .../20180626175335_add_name_to_restaurants.rb | 5 ++++ db/schema.rb | 27 +++++++++++++++++++ db/seeds.rb | 11 ++++++++ .../restaurants_controller_test.rb | 7 +++++ test/fixtures/restaurants.yml | 17 ++++++++++++ test/models/restaurant_test.rb | 7 +++++ 15 files changed, 111 insertions(+) create mode 100644 app/assets/javascripts/restaurants.coffee create mode 100644 app/assets/stylesheets/restaurants.scss create mode 100644 app/controllers/restaurants_controller.rb create mode 100644 app/helpers/restaurants_helper.rb create mode 100644 app/models/restaurant.rb create mode 100644 app/views/restaurants/index.html.erb create mode 100644 app/views/restaurants/show.html.erb create mode 100644 db/migrate/20180626174750_create_restaurants.rb create mode 100644 db/migrate/20180626175335_add_name_to_restaurants.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/restaurants_controller_test.rb create mode 100644 test/fixtures/restaurants.yml create mode 100644 test/models/restaurant_test.rb diff --git a/app/assets/javascripts/restaurants.coffee b/app/assets/javascripts/restaurants.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/restaurants.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/restaurants.scss b/app/assets/stylesheets/restaurants.scss new file mode 100644 index 00000000..18555c87 --- /dev/null +++ b/app/assets/stylesheets/restaurants.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Restaurants 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/restaurants_controller.rb b/app/controllers/restaurants_controller.rb new file mode 100644 index 00000000..353b943c --- /dev/null +++ b/app/controllers/restaurants_controller.rb @@ -0,0 +1,5 @@ +class RestaurantsController < ApplicationController + def index + @restaurants = Restaurant.all + end +end diff --git a/app/helpers/restaurants_helper.rb b/app/helpers/restaurants_helper.rb new file mode 100644 index 00000000..3937c4c7 --- /dev/null +++ b/app/helpers/restaurants_helper.rb @@ -0,0 +1,2 @@ +module RestaurantsHelper +end diff --git a/app/models/restaurant.rb b/app/models/restaurant.rb new file mode 100644 index 00000000..ee1243c7 --- /dev/null +++ b/app/models/restaurant.rb @@ -0,0 +1,2 @@ +class Restaurant < ApplicationRecord +end diff --git a/app/views/restaurants/index.html.erb b/app/views/restaurants/index.html.erb new file mode 100644 index 00000000..299ec545 --- /dev/null +++ b/app/views/restaurants/index.html.erb @@ -0,0 +1,5 @@ +

Index Page

+<% @restaurants.each do |restaurant| %> +

<%= restaurant.name %>

+

<%= restaurant.neighbourhood %>

+<% end %> diff --git a/app/views/restaurants/show.html.erb b/app/views/restaurants/show.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/config/routes.rb b/config/routes.rb index 787824f8..dd2efd28 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 "restaurants#index" + + resources :restaurants end diff --git a/db/migrate/20180626174750_create_restaurants.rb b/db/migrate/20180626174750_create_restaurants.rb new file mode 100644 index 00000000..ce8dd869 --- /dev/null +++ b/db/migrate/20180626174750_create_restaurants.rb @@ -0,0 +1,14 @@ +class CreateRestaurants < ActiveRecord::Migration[5.0] + def change + create_table :restaurants do |t| + t.string :address + t.string :neighbourhood + t.integer :price_range + t.text :summary + t.text :menu + t.datetime :time_slots + + t.timestamps + end + end +end diff --git a/db/migrate/20180626175335_add_name_to_restaurants.rb b/db/migrate/20180626175335_add_name_to_restaurants.rb new file mode 100644 index 00000000..adf2627b --- /dev/null +++ b/db/migrate/20180626175335_add_name_to_restaurants.rb @@ -0,0 +1,5 @@ +class AddNameToRestaurants < ActiveRecord::Migration[5.0] + def change + add_column :restaurants, :name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..91d4fc39 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,27 @@ +# 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: 20180626175335) do + + create_table "restaurants", force: :cascade do |t| + t.string "address" + t.string "neighbourhood" + t.integer "price_range" + t.text "summary" + t.text "menu" + t.datetime "time_slots" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name" + end + +end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e85..b86c8d2b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,14 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + +Restaurant.create!(name: "Burger-Place", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) +Restaurant.create!(name: "Pizza-Place", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) +Restaurant.create!(name: "Fry-Place", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) +Restaurant.create!(name: "Ramen-Spot", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) +Restaurant.create!(name: "Sushi-Palace", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) +Restaurant.create!(name: "Burger-Place", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) +Restaurant.create!(name: "Italian-Place", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) +Restaurant.create!(name: "Chinese-Place", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) +Restaurant.create!(name: "Mexican-Place", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) +Restaurant.create!(name: "Salad-Place", neighbourhood: "Westdale", price_range: 5, summary: "test", menu: "test", time_slots: nil) diff --git a/test/controllers/restaurants_controller_test.rb b/test/controllers/restaurants_controller_test.rb new file mode 100644 index 00000000..c0e4d28e --- /dev/null +++ b/test/controllers/restaurants_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RestaurantsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/restaurants.yml b/test/fixtures/restaurants.yml new file mode 100644 index 00000000..e4564eed --- /dev/null +++ b/test/fixtures/restaurants.yml @@ -0,0 +1,17 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + address: MyString + neighbourhood: MyString + price_range: 1 + summary: MyText + menu: MyText + time_slots: 2018-06-26 13:47:51 + +two: + address: MyString + neighbourhood: MyString + price_range: 1 + summary: MyText + menu: MyText + time_slots: 2018-06-26 13:47:51 diff --git a/test/models/restaurant_test.rb b/test/models/restaurant_test.rb new file mode 100644 index 00000000..b45b7417 --- /dev/null +++ b/test/models/restaurant_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RestaurantTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From 65f45c1ad2ae459a5050aac26ad8038158fbf681 Mon Sep 17 00:00:00 2001 From: Kevin LeBlanc Date: Tue, 26 Jun 2018 15:03:18 -0400 Subject: [PATCH 3/5] Add new_user form. Add authentication. Remembered 'has_secure_password' --- Gemfile | 3 +-- Gemfile.lock | 2 ++ app/assets/javascripts/users.coffee | 3 +++ app/assets/stylesheets/users.scss | 3 +++ app/controllers/restaurants_controller.rb | 5 +++++ app/controllers/users_controller.rb | 24 +++++++++++++++++++++++ app/helpers/users_helper.rb | 2 ++ app/models/user.rb | 3 +++ app/views/restaurants/index.html.erb | 3 ++- app/views/restaurants/show.html.erb | 10 ++++++++++ app/views/users/_form.html.erb | 13 ++++++++++++ app/views/users/new.html.erb | 2 ++ config/routes.rb | 2 ++ db/migrate/20180626182734_create_users.rb | 9 +++++++++ db/schema.rb | 9 ++++++++- test/controllers/users_controller_test.rb | 7 +++++++ test/fixtures/users.yml | 11 +++++++++++ test/models/user_test.rb | 7 +++++++ 18 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/users.coffee create mode 100644 app/assets/stylesheets/users.scss create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/models/user.rb create mode 100644 app/views/users/_form.html.erb create mode 100644 app/views/users/new.html.erb create mode 100644 db/migrate/20180626182734_create_users.rb create mode 100644 test/controllers/users_controller_test.rb create mode 100644 test/fixtures/users.yml create mode 100644 test/models/user_test.rb diff --git a/Gemfile b/Gemfile index fecd89c7..215a6fa4 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ gem 'jbuilder', '~> 2.0' gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' +gem 'bcrypt', '~> 3.1.7' # Use Unicorn as the app server # gem 'unicorn' @@ -42,4 +42,3 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end - diff --git a/Gemfile.lock b/Gemfile.lock index 0a81632e..84d3661f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,6 +39,7 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) + bcrypt (3.1.12) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) builder (3.2.3) @@ -156,6 +157,7 @@ PLATFORMS ruby DEPENDENCIES + bcrypt (~> 3.1.7) byebug coffee-rails (~> 4.1.0) jbuilder (~> 2.0) diff --git a/app/assets/javascripts/users.coffee b/app/assets/javascripts/users.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/users.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 00000000..31a2eacb --- /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/restaurants_controller.rb b/app/controllers/restaurants_controller.rb index 353b943c..0f5c9a89 100644 --- a/app/controllers/restaurants_controller.rb +++ b/app/controllers/restaurants_controller.rb @@ -2,4 +2,9 @@ class RestaurantsController < ApplicationController def index @restaurants = Restaurant.all end + + def show + @restaurant = Restaurant.find(params[:id]) + end + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 00000000..25b0a79d --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,24 @@ +class UsersController < ApplicationController + def new + @user = User.new + end + + def create + submitted_email = params[:user][:email] + submitted_password = params[:user][:password] + submitted_password_confirmation = params[:user][:password_confirmation] + + @user = User.new + + @user.email = params[:user][:email] + @user.password = params[:user][:password] + @user.password_confirmation = params[:user][:password_confirmation] + + if @user.save + redirect_to root_url + else + render :new + end + end + +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 00000000..2310a240 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 00000000..d67da206 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,3 @@ +class User < ApplicationRecord + has_secure_password +end diff --git a/app/views/restaurants/index.html.erb b/app/views/restaurants/index.html.erb index 299ec545..3237cd5c 100644 --- a/app/views/restaurants/index.html.erb +++ b/app/views/restaurants/index.html.erb @@ -1,5 +1,6 @@

Index Page

+<%= link_to "Signup", new_users_path %> <% @restaurants.each do |restaurant| %> -

<%= restaurant.name %>

+

<%= link_to restaurant.name, restaurant_path(restaurant) %>

<%= restaurant.neighbourhood %>

<% end %> diff --git a/app/views/restaurants/show.html.erb b/app/views/restaurants/show.html.erb index e69de29b..dc65074a 100644 --- a/app/views/restaurants/show.html.erb +++ b/app/views/restaurants/show.html.erb @@ -0,0 +1,10 @@ +<%= link_to "Back", restaurants_path %> + +

Show Page

+

<%= @restaurant.name %>

+

<%= @restaurant.neighbourhood %>

+

<%= @restaurant.address %>

+

<%= @restaurant.price_range %>

+

<%= @restaurant.summary %>

+

<%= @restaurant.menu %>

+

<%= @restaurant.time_slots %>

diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb new file mode 100644 index 00000000..4b49bfb1 --- /dev/null +++ b/app/views/users/_form.html.erb @@ -0,0 +1,13 @@ +<%= form_for user do |f| %> + +

<%= f.label :email %>

+

<%= f.text_field :email %>

+ +

<%= f.label :password %>

+

<%= f.password_field :password %>

+ +

<%= f.label :password %>

+

<%= f.password_field :password %>

+ +

<%= f.submit %>

+<% end %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 00000000..63f3d8f9 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,2 @@ +

New Customer

+<%= render "form", user: @user %> diff --git a/config/routes.rb b/config/routes.rb index dd2efd28..95fcde58 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,4 +3,6 @@ root "restaurants#index" resources :restaurants + + resource :users end diff --git a/db/migrate/20180626182734_create_users.rb b/db/migrate/20180626182734_create_users.rb new file mode 100644 index 00000000..95c09a6a --- /dev/null +++ b/db/migrate/20180626182734_create_users.rb @@ -0,0 +1,9 @@ +class CreateUsers < ActiveRecord::Migration[5.0] + def change + create_table :users do |t| + t.string "email" + t.string "password_digest" + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 91d4fc39..a66f1999 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: 20180626175335) do +ActiveRecord::Schema.define(version: 20180626182734) do create_table "restaurants", force: :cascade do |t| t.string "address" @@ -24,4 +24,11 @@ t.string "name" end + create_table "users", force: :cascade do |t| + t.string "email" + t.string "password_digest" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + end diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 00000000..6c3da770 --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UsersControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 00000000..80aed36e --- /dev/null +++ b/test/fixtures/users.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/user_test.rb b/test/models/user_test.rb new file mode 100644 index 00000000..82f61e01 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From f5aac89588a714d0189704049049f3f41e12c9b9 Mon Sep 17 00:00:00 2001 From: Kevin LeBlanc Date: Tue, 26 Jun 2018 15:35:05 -0400 Subject: [PATCH 4/5] Add sessions conroller. Add Sign In form. Add owner? column to Users table --- app/assets/javascripts/sessions.coffee | 3 +++ app/assets/stylesheets/sessions.scss | 3 +++ app/controllers/application_controller.rb | 9 +++++++ app/controllers/sessions_controller.rb | 24 +++++++++++++++++++ app/helpers/sessions_helper.rb | 2 ++ app/views/layouts/application.html.erb | 9 +++++++ app/views/restaurants/index.html.erb | 1 - app/views/sessions/new.html.erb | 15 ++++++++++++ config/routes.rb | 2 ++ .../20180626191220_add_column_to_user.rb | 5 ++++ db/schema.rb | 3 ++- test/controllers/sessions_controller_test.rb | 7 ++++++ 12 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/sessions.coffee create mode 100644 app/assets/stylesheets/sessions.scss create mode 100644 app/controllers/sessions_controller.rb create mode 100644 app/helpers/sessions_helper.rb create mode 100644 app/views/sessions/new.html.erb create mode 100644 db/migrate/20180626191220_add_column_to_user.rb create mode 100644 test/controllers/sessions_controller_test.rb diff --git a/app/assets/javascripts/sessions.coffee b/app/assets/javascripts/sessions.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/sessions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 00000000..7bef9cf8 --- /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/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e1..2e05c1e9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,13 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + helper_method :current_user + + private + + def current_user + user_id = session[:user_id] + user_id && User.find(user_id) + end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 00000000..75c6ce28 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,24 @@ +class SessionsController < ApplicationController + def new + + end + + def create + user = User.find_by(email: params[:sessions][:email]) + + if user && user.authenticate(params[:sessions][:password]) + + session[:user_id] = user.id + + redirect_to root_url + else + render :new_users_path + end + + end + + def destroy + session[:user_id] = nil + redirect_to root_url + end +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 00000000..309f8b2e --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c32feae9..db66a5f4 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,6 +6,15 @@ <%= javascript_include_tag 'application' %> <%= csrf_meta_tags %> + <%= yield %> diff --git a/app/views/restaurants/index.html.erb b/app/views/restaurants/index.html.erb index 3237cd5c..dfc9bb94 100644 --- a/app/views/restaurants/index.html.erb +++ b/app/views/restaurants/index.html.erb @@ -1,5 +1,4 @@

Index Page

-<%= link_to "Signup", new_users_path %> <% @restaurants.each do |restaurant| %>

<%= link_to restaurant.name, restaurant_path(restaurant) %>

<%= restaurant.neighbourhood %>

diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 00000000..3883c670 --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,15 @@ +

Sign In

+<%= form_for :sessions, url: session_path do |f| %> + +
+ <%= f.label :email %> + <%= f.email_field :email %> +
+
+ <%= f.label :password %> + <%= f.password_field :password %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 95fcde58..f8ed7859 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,4 +5,6 @@ resources :restaurants resource :users + + resource :session, only: %i(new create destroy) end diff --git a/db/migrate/20180626191220_add_column_to_user.rb b/db/migrate/20180626191220_add_column_to_user.rb new file mode 100644 index 00000000..1cf42ec5 --- /dev/null +++ b/db/migrate/20180626191220_add_column_to_user.rb @@ -0,0 +1,5 @@ +class AddColumnToUser < ActiveRecord::Migration[5.0] + def change + add_column :users, :owner?, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index a66f1999..25f03c44 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: 20180626182734) do +ActiveRecord::Schema.define(version: 20180626191220) do create_table "restaurants", force: :cascade do |t| t.string "address" @@ -29,6 +29,7 @@ t.string "password_digest" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "owner?" end end diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 00000000..6135ce6a --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SessionsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end From 0a8c7567696aa7e26d1b02abb20d502a3683d2df Mon Sep 17 00:00:00 2001 From: hibernatingnerd Date: Tue, 26 Jun 2018 17:32:43 -0400 Subject: [PATCH 5/5] added reservation model, controller and form. --- app/assets/javascripts/reservations.coffee | 3 +++ app/assets/stylesheets/reservations.scss | 3 +++ app/controllers/application_controller.rb | 1 + app/controllers/reservations_controller.rb | 24 +++++++++++++++++++ app/helpers/reservations_helper.rb | 2 ++ app/models/reservation.rb | 4 ++++ app/models/restaurant.rb | 2 ++ app/models/user.rb | 3 +++ app/views/reservations/new.html.erb | 14 +++++++++++ app/views/restaurants/show.html.erb | 2 ++ config/routes.rb | 7 +++++- .../20180626200503_create_reservations.rb | 13 ++++++++++ db/schema.rb | 12 +++++++++- seatyourself | 1 + .../reservations_controller_test.rb | 7 ++++++ test/fixtures/reservations.yml | 15 ++++++++++++ test/models/reservation_test.rb | 7 ++++++ 17 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/reservations.coffee create mode 100644 app/assets/stylesheets/reservations.scss create mode 100644 app/controllers/reservations_controller.rb create mode 100644 app/helpers/reservations_helper.rb create mode 100644 app/models/reservation.rb create mode 100644 app/views/reservations/new.html.erb create mode 100644 db/migrate/20180626200503_create_reservations.rb create mode 160000 seatyourself create mode 100644 test/controllers/reservations_controller_test.rb create mode 100644 test/fixtures/reservations.yml create mode 100644 test/models/reservation_test.rb diff --git a/app/assets/javascripts/reservations.coffee b/app/assets/javascripts/reservations.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/reservations.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/reservations.scss b/app/assets/stylesheets/reservations.scss new file mode 100644 index 00000000..64d990d2 --- /dev/null +++ b/app/assets/stylesheets/reservations.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reservations 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/application_controller.rb b/app/controllers/application_controller.rb index 2e05c1e9..9f46a203 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,4 +11,5 @@ def current_user user_id = session[:user_id] user_id && User.find(user_id) end + end diff --git a/app/controllers/reservations_controller.rb b/app/controllers/reservations_controller.rb new file mode 100644 index 00000000..20fd13f7 --- /dev/null +++ b/app/controllers/reservations_controller.rb @@ -0,0 +1,24 @@ +class ReservationsController < ApplicationController + + def new + @reservation = Reservation.new + @restaurant = Restaurant.find(params[:restaurant_id]) + end + + def create + @restaurant = Restaurant.find(params[:restaurant_id]) + @reservation = Reservation.new + + @reservation.date = params[:reservation][:date] + @reservation.time = params[:reservation][:time] + @reservation.user_id = session[:user_id] + @reservation.restaurant_id = @restaurant.id + + if @reservation.save + redirect_to root_url + else + render :new + end + end + +end diff --git a/app/helpers/reservations_helper.rb b/app/helpers/reservations_helper.rb new file mode 100644 index 00000000..f28b699d --- /dev/null +++ b/app/helpers/reservations_helper.rb @@ -0,0 +1,2 @@ +module ReservationsHelper +end diff --git a/app/models/reservation.rb b/app/models/reservation.rb new file mode 100644 index 00000000..a5e9a4a2 --- /dev/null +++ b/app/models/reservation.rb @@ -0,0 +1,4 @@ +class Reservation < ApplicationRecord + belongs_to :user + belongs_to :restaurant +end diff --git a/app/models/restaurant.rb b/app/models/restaurant.rb index ee1243c7..a8955eb8 100644 --- a/app/models/restaurant.rb +++ b/app/models/restaurant.rb @@ -1,2 +1,4 @@ class Restaurant < ApplicationRecord + has_many :reservations + has_many :users, through: :reservations end diff --git a/app/models/user.rb b/app/models/user.rb index d67da206..429a8d5e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,6 @@ class User < ApplicationRecord has_secure_password + has_many :reservations + has_many :restaurants, through: :reservations + end diff --git a/app/views/reservations/new.html.erb b/app/views/reservations/new.html.erb new file mode 100644 index 00000000..8eaa52a6 --- /dev/null +++ b/app/views/reservations/new.html.erb @@ -0,0 +1,14 @@ +<%= form_for [@restaurant, @reservation] do |f| %> + +<%= f.label :date %> +<%= f.date_field :date %> + +<%= f.label :time %> +<%= f.time_select :time %> + +<%= f.label :partysize %> +<%= f.text_field :partysize %> + +<%= f.submit %> + +<% end %> diff --git a/app/views/restaurants/show.html.erb b/app/views/restaurants/show.html.erb index dc65074a..a8e32a2e 100644 --- a/app/views/restaurants/show.html.erb +++ b/app/views/restaurants/show.html.erb @@ -8,3 +8,5 @@

<%= @restaurant.summary %>

<%= @restaurant.menu %>

<%= @restaurant.time_slots %>

+ +<%= link_to "make a reservation!", new_restaurant_reservation_path(@restaurant) %> diff --git a/config/routes.rb b/config/routes.rb index f8ed7859..aefd6a02 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,9 +2,14 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root "restaurants#index" - resources :restaurants + resources :restaurants do + resources :reservations + + end resource :users resource :session, only: %i(new create destroy) + + end diff --git a/db/migrate/20180626200503_create_reservations.rb b/db/migrate/20180626200503_create_reservations.rb new file mode 100644 index 00000000..74f13311 --- /dev/null +++ b/db/migrate/20180626200503_create_reservations.rb @@ -0,0 +1,13 @@ +class CreateReservations < ActiveRecord::Migration[5.0] + def change + create_table :reservations do |t| + t.integer :user_id + t.integer :restaurant_id + t.integer :partysize + t.date :date + t.time :time + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 25f03c44..9adc6d2b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,17 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180626191220) do +ActiveRecord::Schema.define(version: 20180626200503) do + + create_table "reservations", force: :cascade do |t| + t.integer "user_id" + t.integer "restaurant_id" + t.integer "partysize" + t.date "date" + t.time "time" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end create_table "restaurants", force: :cascade do |t| t.string "address" diff --git a/seatyourself b/seatyourself new file mode 160000 index 00000000..f5aac895 --- /dev/null +++ b/seatyourself @@ -0,0 +1 @@ +Subproject commit f5aac89588a714d0189704049049f3f41e12c9b9 diff --git a/test/controllers/reservations_controller_test.rb b/test/controllers/reservations_controller_test.rb new file mode 100644 index 00000000..3b4d21b6 --- /dev/null +++ b/test/controllers/reservations_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ReservationsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/reservations.yml b/test/fixtures/reservations.yml new file mode 100644 index 00000000..d3145cf1 --- /dev/null +++ b/test/fixtures/reservations.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + user_id: 1 + restaurant_id: 1 + partysize: 1 + date: 2018-06-26 + time: 2018-06-26 16:05:03 + +two: + user_id: 1 + restaurant_id: 1 + partysize: 1 + date: 2018-06-26 + time: 2018-06-26 16:05:03 diff --git a/test/models/reservation_test.rb b/test/models/reservation_test.rb new file mode 100644 index 00000000..391559fd --- /dev/null +++ b/test/models/reservation_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ReservationTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end