From 9d17166e8f92ed69e1cb53b5f23d5bb44073ebe4 Mon Sep 17 00:00:00 2001 From: Okechi Onyeje Date: Thu, 19 Jan 2017 15:42:49 -0500 Subject: [PATCH] Dashboard integrated but with errors - authentication routes are glitchy - custom devise views are not being displayed properly - routing issues and custom fields for devise routes and models --- Pearlception/.pryrc | 4 +++ Pearlception/Gemfile | 14 +++++++++ Pearlception/Gemfile.lock | 31 +++++++++++++++++++ .../app/assets/stylesheets/custom.scss | 22 +++++++++++++ .../app/controllers/dashboard_controller.rb | 7 ++++- .../controllers/registrations_controller.rb | 8 ++++- .../app/helpers/application_helper.rb | 11 +++++++ Pearlception/app/models/oyster.rb | 11 +++++-- Pearlception/app/models/result.rb | 9 +++++- Pearlception/app/models/run.rb | 10 +++++- Pearlception/app/models/user.rb | 2 ++ .../app/views/dashboard/index.html.erb | 15 ++++++--- .../app/views/layouts/application.html.erb | 14 ++++----- .../app/views/users/sessions/new.html.erb | 2 +- Pearlception/config/database.yml | 18 +++++++++-- Pearlception/config/routes.rb | 9 ++++-- ...9161737_change_company_id_type_in_users.rb | 5 +++ Pearlception/db/schema.rb | 19 +++++------- 18 files changed, 175 insertions(+), 36 deletions(-) create mode 100644 Pearlception/.pryrc create mode 100644 Pearlception/app/assets/stylesheets/custom.scss create mode 100644 Pearlception/db/migrate/20170119161737_change_company_id_type_in_users.rb diff --git a/Pearlception/.pryrc b/Pearlception/.pryrc new file mode 100644 index 0000000..a95f43e --- /dev/null +++ b/Pearlception/.pryrc @@ -0,0 +1,4 @@ +if Rails.env.development? || Rails.env.test? + # This introduces the `table` statement + extend Hirb::Console +end diff --git a/Pearlception/Gemfile b/Pearlception/Gemfile index 9a447a8..e334ea2 100644 --- a/Pearlception/Gemfile +++ b/Pearlception/Gemfile @@ -49,7 +49,21 @@ 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 'awesome_rails_console' + gem 'hirb' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +# Please clean up duplicated gems if any. +# Feel free to remove gems that you don't want to use or if they conflict with other gem dependencies. (you might need to update .pryrc also) +group :development, :test do + gem 'hirb' + gem 'hirb-unicode' + gem 'pry-byebug' + gem 'pry-stack_explorer' +end + +group :development, :test do +end diff --git a/Pearlception/Gemfile.lock b/Pearlception/Gemfile.lock index 7b37024..47ab8e3 100644 --- a/Pearlception/Gemfile.lock +++ b/Pearlception/Gemfile.lock @@ -39,9 +39,17 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) + awesome_print (1.7.0) + awesome_rails_console (0.4.0) + awesome_print + pry-rails + railties bcrypt (3.1.11) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) builder (3.2.2) byebug (9.0.6) + coderay (1.1.1) coffee-rails (4.2.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.2.x) @@ -62,6 +70,10 @@ GEM ffi (1.9.14) globalid (0.3.7) activesupport (>= 4.1.0) + hirb (0.7.3) + hirb-unicode (0.0.5) + hirb (~> 0.5) + unicode-display_width (~> 0.1.1) i18n (0.7.0) jbuilder (2.6.1) activesupport (>= 3.0.0, < 5.1) @@ -89,6 +101,18 @@ GEM nokogiri (1.7.0) mini_portile2 (~> 2.1.0) orm_adapter (0.5.0) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-byebug (3.4.2) + byebug (~> 9.0) + pry (~> 0.10) + pry-rails (0.3.4) + pry (>= 0.9.10) + pry-stack_explorer (0.4.9.2) + binding_of_caller (>= 0.7) + pry (>= 0.9.11) puma (3.6.2) rack (2.0.1) rack-test (0.6.3) @@ -129,6 +153,7 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + slop (3.6.0) spring (2.0.0) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -151,6 +176,7 @@ GEM thread_safe (~> 0.1) uglifier (3.0.4) execjs (>= 0.3.0, < 3) + unicode-display_width (0.1.1) warden (1.2.6) rack (>= 1.0) web-console (3.4.0) @@ -166,14 +192,19 @@ PLATFORMS ruby DEPENDENCIES + awesome_rails_console bcrypt (~> 3.1.7) byebug coffee-rails (~> 4.2) devise + hirb + hirb-unicode jbuilder (~> 2.5) jquery-rails listen (~> 3.0.5) mysql2 (>= 0.3.18, < 0.5) + pry-byebug + pry-stack_explorer puma (~> 3.0) rails (~> 5.0.1) sass-rails (~> 5.0) diff --git a/Pearlception/app/assets/stylesheets/custom.scss b/Pearlception/app/assets/stylesheets/custom.scss new file mode 100644 index 0000000..0f37419 --- /dev/null +++ b/Pearlception/app/assets/stylesheets/custom.scss @@ -0,0 +1,22 @@ +//@import "bootstrap-sprockets"; +@import "bootstrap"; + +/* mixins, variables, etc. */ + +$gray-medium-light: #eaeaea; + +@mixin box_sizing { + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} + +/* miscellaneous */ + +.debug_dump { + clear: both; + float: left; + width: 100%; + margin-top: 45px; + @include box_sizing; +} diff --git a/Pearlception/app/controllers/dashboard_controller.rb b/Pearlception/app/controllers/dashboard_controller.rb index 573a03c..bc5e667 100644 --- a/Pearlception/app/controllers/dashboard_controller.rb +++ b/Pearlception/app/controllers/dashboard_controller.rb @@ -1,7 +1,12 @@ class DashboardController < ApplicationController + before_filter :deny_to_visitors def index - + + end + + def deny_to_visitors + redirect_to "/signin" unless user_signed_in? end end diff --git a/Pearlception/app/controllers/registrations_controller.rb b/Pearlception/app/controllers/registrations_controller.rb index b97cbdf..48c6d01 100644 --- a/Pearlception/app/controllers/registrations_controller.rb +++ b/Pearlception/app/controllers/registrations_controller.rb @@ -1,5 +1,11 @@ class RegistrationsController < Devise::RegistrationsController - private + include ApplicationHelper + protected + + def create + super + binding.pry + end def sign_up_params params.require(:user).permit(:company_id, :email, :password, :password_confirmation) diff --git a/Pearlception/app/helpers/application_helper.rb b/Pearlception/app/helpers/application_helper.rb index de6be79..2768dce 100644 --- a/Pearlception/app/helpers/application_helper.rb +++ b/Pearlception/app/helpers/application_helper.rb @@ -1,2 +1,13 @@ module ApplicationHelper + def resource_name + :user + end + + def resource + @resource ||= User.new + end + + def devise_mapping + @devise_mapping ||= Devise.mappings[:user] + end end diff --git a/Pearlception/app/models/oyster.rb b/Pearlception/app/models/oyster.rb index 0a7cdb6..3514394 100644 --- a/Pearlception/app/models/oyster.rb +++ b/Pearlception/app/models/oyster.rb @@ -1,6 +1,11 @@ class Oyster < ApplicationRecord belongs_to :run - Oyster.establish_connection(:"stats_#{Rails.env}") - - + #Oyster.establish_connection(:"stats_#{Rails.env}") + Oyster.establish_connection( + :adapter => "mysql2", + :host => ENV['STATS_DB_URL'], + :username => ENV['STATS_DB_USER'], + :password => ENV['STATS_DB_PASS'], + :database => "main" + ) end diff --git a/Pearlception/app/models/result.rb b/Pearlception/app/models/result.rb index f03b554..cbd0ed2 100644 --- a/Pearlception/app/models/result.rb +++ b/Pearlception/app/models/result.rb @@ -1,3 +1,10 @@ class Result < ApplicationRecord - establish_connection(:"stats_#{Rails.env}") + #establish_connection(:"stats_#{Rails.env}") + Result.establish_connection( + :adapter => "mysql2", + :host => ENV['STATS_DB_URL'], + :username => ENV['STATS_DB_USER'], + :password => ENV['STATS_DB_PASS'], + :database => "main" + ) end diff --git a/Pearlception/app/models/run.rb b/Pearlception/app/models/run.rb index 18c81f6..1dd5a5e 100644 --- a/Pearlception/app/models/run.rb +++ b/Pearlception/app/models/run.rb @@ -1,4 +1,12 @@ class Run < ApplicationRecord has_many :oysters - establish_connection(:"stats_#{Rails.env}") + belongs_to :companies + # establish_connection(:"stats_#{Rails.env}") + Run.establish_connection( + :adapter => "mysql2", + :host => ENV['STATS_DB_URL'], + :username => ENV['STATS_DB_USER'], + :password => ENV['STATS_DB_PASS'], + :database => "main" + ) end diff --git a/Pearlception/app/models/user.rb b/Pearlception/app/models/user.rb index b2091f9..0a39c7f 100644 --- a/Pearlception/app/models/user.rb +++ b/Pearlception/app/models/user.rb @@ -1,4 +1,6 @@ class User < ApplicationRecord + has_one :company + has_many :runs # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, diff --git a/Pearlception/app/views/dashboard/index.html.erb b/Pearlception/app/views/dashboard/index.html.erb index 50c91ed..be38ebf 100644 --- a/Pearlception/app/views/dashboard/index.html.erb +++ b/Pearlception/app/views/dashboard/index.html.erb @@ -14,10 +14,15 @@

Pearlception Dashboard

-
+

Recent Results

diff --git a/Pearlception/app/views/layouts/application.html.erb b/Pearlception/app/views/layouts/application.html.erb index 368cf4a..5978e7f 100644 --- a/Pearlception/app/views/layouts/application.html.erb +++ b/Pearlception/app/views/layouts/application.html.erb @@ -6,17 +6,17 @@ <%= javascript_include_tag "application", "data-turbolinks-track" => false %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> - <%= yield %> + <% if notice %> +

<%= notice %>

+ <% end %> + <% if alert %> +

<%= alert %>

+ <% end %> - <% if notice %> -

<%= notice %>

- <% end %> - <% if alert %> -

<%= alert %>

- <% end %> <%= yield %> + <%= debug(params) if Rails.env.development? %> diff --git a/Pearlception/app/views/users/sessions/new.html.erb b/Pearlception/app/views/users/sessions/new.html.erb index f28053e..d6fde2b 100644 --- a/Pearlception/app/views/users/sessions/new.html.erb +++ b/Pearlception/app/views/users/sessions/new.html.erb @@ -1,4 +1,4 @@ -

Log in

+

Log

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
diff --git a/Pearlception/config/database.yml b/Pearlception/config/database.yml index 04d2385..5c38342 100644 --- a/Pearlception/config/database.yml +++ b/Pearlception/config/database.yml @@ -15,13 +15,13 @@ default: &default pool: 5 username: <%= ENV['TEST_USER'] %> password: <%= ENV['TEST_PASS'] %> - socket: <%= ENV['TEST_SOCKET'] %> + socket: <%= ENV['TEST_SOCKET'] %> -stats_development: &stats +stats_development: &stats adapter: mysql2 encoding: utf8 pool: 5 - username: <%= ENV['STATS_DB_USER'] %> + username: <%= ENV['STATS_DB_USER'] %> password: <%= ENV['STATS_DB_PASS'] %> host: <%= ENV['STATS_DB_URL'] %> port: 3306 @@ -34,6 +34,12 @@ stats_test: development: <<: *default database: Pearlception_development + username: <%= ENV['DEV_DB_USER'] %> + password: <%= ENV['DEV_DB_PASS'] %> + #host: <%= ENV['DEV_DB_URL'] %> + host: localhost + port: 3306 + #database: main # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -41,6 +47,12 @@ development: test: <<: *default database: Pearlception_test + username: <%= ENV['DEV_DB_USER'] %> + password: <%= ENV['DEV_DB_PASS'] %> + #host: <%= ENV['DEV_DB_URL'] %> + host: localhost + port: 3306 + #database: main # 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 diff --git a/Pearlception/config/routes.rb b/Pearlception/config/routes.rb index 38cd3e6..625aa85 100644 --- a/Pearlception/config/routes.rb +++ b/Pearlception/config/routes.rb @@ -1,7 +1,12 @@ Rails.application.routes.draw do - devise_for :users, :controllers => { registrations: 'registrations' } root "dashboard#index" resources :runs + + devise_for :users, :controllers => {:registrations => 'registrations'} + devise_scope :users do + get 'signin' => 'registrations#new' + post 'signin' => 'registrations#create' + end # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html -end \ No newline at end of file +end diff --git a/Pearlception/db/migrate/20170119161737_change_company_id_type_in_users.rb b/Pearlception/db/migrate/20170119161737_change_company_id_type_in_users.rb new file mode 100644 index 0000000..8fb396d --- /dev/null +++ b/Pearlception/db/migrate/20170119161737_change_company_id_type_in_users.rb @@ -0,0 +1,5 @@ +class ChangeCompanyIdTypeInUsers < ActiveRecord::Migration[5.0] + def change + change_column :users, :company_id, :integer, default: -1 + end +end diff --git a/Pearlception/db/schema.rb b/Pearlception/db/schema.rb index 11318a1..bb71542 100644 --- a/Pearlception/db/schema.rb +++ b/Pearlception/db/schema.rb @@ -10,8 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -<<<<<<< HEAD -ActiveRecord::Schema.define(version: 20170109174008) do +ActiveRecord::Schema.define(version: 20170119161737) do create_table "companies", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.string "company_name" @@ -21,24 +20,22 @@ ActiveRecord::Schema.define(version: 20170109174008) do end create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.integer "company_id", null: false + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.integer "company_id", null: false + t.boolean "admin", default: false, null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["email"], name: "index_users_on_email", unique: true, using: :btree t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree end -======= -ActiveRecord::Schema.define(version: 0) do ->>>>>>> master end