From 7d52ef34f55567aeb4b35ab67d9f6fdae7370a36 Mon Sep 17 00:00:00 2001 From: Mini Robot Date: Fri, 19 Jan 2018 15:51:19 +0100 Subject: [PATCH] second --- Gemfile | 2 + Gemfile.lock | 3 + app/assets/javascripts/home.coffee | 3 + app/assets/stylesheets/home.scss | 3 + app/controllers/home_controller.rb | 4 + app/helpers/home_helper.rb | 2 + app/views/home/index.html.erb | 2 + config/database.yml | 12 +-- config/initializers/friendly_id.rb | 88 +++++++++++++++++++ config/puma.rb | 2 +- config/routes.rb | 3 + ...20180119143920_create_friendly_id_slugs.rb | 15 ++++ db/schema.rb | 27 ++++++ test/controllers/home_controller_test.rb | 9 ++ 14 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 app/assets/javascripts/home.coffee create mode 100644 app/assets/stylesheets/home.scss create mode 100644 app/controllers/home_controller.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/views/home/index.html.erb create mode 100644 config/initializers/friendly_id.rb create mode 100644 db/migrate/20180119143920_create_friendly_id_slugs.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/home_controller_test.rb diff --git a/Gemfile b/Gemfile index ca18d67..33f8ada 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,8 @@ gem 'rails', '~> 5.1.4' # Use mysql as the database for Active Record gem 'mysql2', '>= 0.3.18', '< 0.5' # Use Puma as the app server +gem 'friendly_id', '~> 5.1.0' + gem 'puma', '~> 3.7' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 33b701d..17bc466 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -65,6 +65,8 @@ GEM erubi (1.7.0) execjs (2.7.0) ffi (1.9.18) + friendly_id (5.1.0) + activerecord (>= 4.0.0) globalid (0.4.1) activesupport (>= 4.2.0) i18n (0.9.1) @@ -178,6 +180,7 @@ DEPENDENCIES byebug capybara (~> 2.13) coffee-rails (~> 4.2) + friendly_id (~> 5.1.0) jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) mysql2 (>= 0.3.18, < 0.5) diff --git a/app/assets/javascripts/home.coffee b/app/assets/javascripts/home.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/home.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/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 0000000..7131aac --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Home 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/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..95f2992 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,4 @@ +class HomeController < ApplicationController + def index + end +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..2085730 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,2 @@ +

Home#index

+

Find me in app/views/home/index.html.erb

diff --git a/config/database.yml b/config/database.yml index 15180f9..034cab8 100644 --- a/config/database.yml +++ b/config/database.yml @@ -12,21 +12,21 @@ default: &default adapter: mysql2 encoding: utf8 - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - username: root - password: - host: localhost + pool: 5 + username: simplecrm_usr + password: CKScvDDtFzdwB4ep + host: 51.254.143.84 development: <<: *default - database: SimpleCrm_development + database: simplecrm # 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: SimpleCrm_test + database: simplecrm_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 diff --git a/config/initializers/friendly_id.rb b/config/initializers/friendly_id.rb new file mode 100644 index 0000000..f064f1e --- /dev/null +++ b/config/initializers/friendly_id.rb @@ -0,0 +1,88 @@ +# FriendlyId Global Configuration +# +# Use this to set up shared configuration options for your entire application. +# Any of the configuration options shown here can also be applied to single +# models by passing arguments to the `friendly_id` class method or defining +# methods in your model. +# +# To learn more, check out the guide: +# +# http://norman.github.io/friendly_id/file.Guide.html + +FriendlyId.defaults do |config| + # ## Reserved Words + # + # Some words could conflict with Rails's routes when used as slugs, or are + # undesirable to allow as slugs. Edit this list as needed for your app. + config.use :reserved + + config.reserved_words = %w(new edit index session login logout users admin + stylesheets assets javascripts images) + + # ## Friendly Finders + # + # Uncomment this to use friendly finders in all models. By default, if + # you wish to find a record by its friendly id, you must do: + # + # MyModel.friendly.find('foo') + # + # If you uncomment this, you can do: + # + # MyModel.find('foo') + # + # This is significantly more convenient but may not be appropriate for + # all applications, so you must explicity opt-in to this behavior. You can + # always also configure it on a per-model basis if you prefer. + # + # Something else to consider is that using the :finders addon boosts + # performance because it will avoid Rails-internal code that makes runtime + # calls to `Module.extend`. + # + # config.use :finders + # + # ## Slugs + # + # Most applications will use the :slugged module everywhere. If you wish + # to do so, uncomment the following line. + # + # config.use :slugged + # + # By default, FriendlyId's :slugged addon expects the slug column to be named + # 'slug', but you can change it if you wish. + # + # config.slug_column = 'slug' + # + # When FriendlyId can not generate a unique ID from your base method, it appends + # a UUID, separated by a single dash. You can configure the character used as the + # separator. If you're upgrading from FriendlyId 4, you may wish to replace this + # with two dashes. + # + # config.sequence_separator = '-' + # + # ## Tips and Tricks + # + # ### Controlling when slugs are generated + # + # As of FriendlyId 5.0, new slugs are generated only when the slug field is + # nil, but if you're using a column as your base method can change this + # behavior by overriding the `should_generate_new_friendly_id` method that + # FriendlyId adds to your model. The change below makes FriendlyId 5.0 behave + # more like 4.0. + # + # config.use Module.new { + # def should_generate_new_friendly_id? + # slug.blank? || _changed? + # end + # } + # + # FriendlyId uses Rails's `parameterize` method to generate slugs, but for + # languages that don't use the Roman alphabet, that's not usually sufficient. + # Here we use the Babosa library to transliterate Russian Cyrillic slugs to + # ASCII. If you use this, don't forget to add "babosa" to your Gemfile. + # + # config.use Module.new { + # def normalize_friendly_id(text) + # text.to_slug.normalize! :transliterations => [:russian, :latin] + # end + # } +end diff --git a/config/puma.rb b/config/puma.rb index 1e19380..020cfa4 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -9,7 +9,7 @@ threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch("PORT") { 4450 } # Specifies the `environment` that Puma will run in. # diff --git a/config/routes.rb b/config/routes.rb index 787824f..555073c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,6 @@ Rails.application.routes.draw do + root 'home#index' + get 'home/index' + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/db/migrate/20180119143920_create_friendly_id_slugs.rb b/db/migrate/20180119143920_create_friendly_id_slugs.rb new file mode 100644 index 0000000..6e7389c --- /dev/null +++ b/db/migrate/20180119143920_create_friendly_id_slugs.rb @@ -0,0 +1,15 @@ +class CreateFriendlyIdSlugs < ActiveRecord::Migration[5.1] + def change + create_table :friendly_id_slugs do |t| + t.string :slug, :null => false + t.integer :sluggable_id, :null => false + t.string :sluggable_type, :limit => 50 + t.string :scope + t.datetime :created_at + end + add_index :friendly_id_slugs, :sluggable_id + add_index :friendly_id_slugs, [:slug, :sluggable_type] + add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], :unique => true + add_index :friendly_id_slugs, :sluggable_type + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..7ac854c --- /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: 20180119143920) do + + create_table "friendly_id_slugs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t| + t.string "slug", null: false + t.integer "sluggable_id", null: false + t.string "sluggable_type", limit: 50 + t.string "scope" + t.datetime "created_at" + t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true + t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type" + t.index ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id" + t.index ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type" + end + +end diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb new file mode 100644 index 0000000..6013b68 --- /dev/null +++ b/test/controllers/home_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class HomeControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get home_index_url + assert_response :success + end + +end