diff --git a/myapp/.gitignore b/myapp/.gitignore
index eb3489a9..ec0b1960 100644
--- a/myapp/.gitignore
+++ b/myapp/.gitignore
@@ -1,15 +1,30 @@
-# See http://help.github.com/ignore-files/ for more about ignoring files.
+# 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
+# git config --global core.excludesfile '~/.gitignore_global'
-# Ignore bundler config
+# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
+/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
-/log/*.log
-/tmp
+/log/*
+/tmp/*
+!/log/.keep
+!/tmp/.keep
+
+# Ignore uploaded files in development
+/storage/*
+
+/node_modules
+/yarn-error.log
+
+/public/assets
+.byebug_history
+
+# Ignore master key for decrypting credentials and more.
+/config/master.key
diff --git a/myapp/Gemfile b/myapp/Gemfile
index 882bd0e1..0682a8a8 100644
--- a/myapp/Gemfile
+++ b/myapp/Gemfile
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
gem 'sidekiq', :path => '..'
-gem 'rails', '5.1.4'
+gem 'rails', '~> 5.2.0'
gem 'puma'
platforms :ruby do
diff --git a/myapp/Rakefile b/myapp/Rakefile
index 1044de59..e85f9139 100644
--- a/myapp/Rakefile
+++ b/myapp/Rakefile
@@ -1,4 +1,6 @@
-#!/usr/bin/env rake
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-require File.expand_path('../config/application', __FILE__)
-Myapp::Application.load_tasks
+require_relative 'config/application'
+
+Rails.application.load_tasks
diff --git a/myapp/app/controllers/application_controller.rb b/myapp/app/controllers/application_controller.rb
index e8065d95..09705d12 100644
--- a/myapp/app/controllers/application_controller.rb
+++ b/myapp/app/controllers/application_controller.rb
@@ -1,3 +1,2 @@
class ApplicationController < ActionController::Base
- protect_from_forgery
end
diff --git a/myapp/app/controllers/work_controller.rb b/myapp/app/controllers/work_controller.rb
index 26b8057f..fcf1b4b3 100644
--- a/myapp/app/controllers/work_controller.rb
+++ b/myapp/app/controllers/work_controller.rb
@@ -9,25 +9,25 @@ class WorkController < ApplicationController
def email
UserMailer.delay_for(30.seconds).greetings(Time.now)
- render :text => 'enqueued'
+ render :plain => 'enqueued'
end
def bulk
Sidekiq::Client.push_bulk('class' => HardWorker,
'args' => [['bob', 1, 1], ['mike', 1, 2]])
- render :text => 'enbulked'
+ render :plain => 'enbulked'
end
def long
50.times do |x|
HardWorker.perform_async('bob', 15, x)
end
- render :text => 'enqueued'
+ render :plain => 'enqueued'
end
def crash
HardWorker.perform_async('crash', 1, Time.now.to_f)
- render :text => 'enqueued'
+ render :plain => 'enqueued'
end
def delayed_post
@@ -39,6 +39,6 @@ class WorkController < ApplicationController
p2 = Post.second
end
p.delay.long_method(p2)
- render :text => 'enqueued'
+ render :plain => 'enqueued'
end
end
diff --git a/myapp/app/views/layouts/application.html.erb b/myapp/app/views/layouts/application.html.erb
index 062dea2e..0f2f3601 100644
--- a/myapp/app/views/layouts/application.html.erb
+++ b/myapp/app/views/layouts/application.html.erb
@@ -1,14 +1,15 @@
-
- Myapp
- <%= stylesheet_link_tag "application", :media => "all" %>
- <%= javascript_include_tag "application" %>
- <%= csrf_meta_tags %>
-
-
+
+ Myapp
+ <%= csrf_meta_tags %>
+ <%= csp_meta_tag %>
-<%= yield %>
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
+
-
+
+ <%= yield %>
+
diff --git a/myapp/bin/bundle b/myapp/bin/bundle
index 66e9889e..f19acf5b 100755
--- a/myapp/bin/bundle
+++ b/myapp/bin/bundle
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path('bundler', 'bundle')
diff --git a/myapp/bin/rails b/myapp/bin/rails
index 5191e692..5badb2fd 100755
--- a/myapp/bin/rails
+++ b/myapp/bin/rails
@@ -1,4 +1,9 @@
#!/usr/bin/env ruby
-APP_PATH = File.expand_path('../../config/application', __FILE__)
+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/myapp/bin/rake b/myapp/bin/rake
index 17240489..d87d5f57 100755
--- a/myapp/bin/rake
+++ b/myapp/bin/rake
@@ -1,4 +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/myapp/bin/setup b/myapp/bin/setup
index acdb2c13..94fd4d79 100755
--- a/myapp/bin/setup
+++ b/myapp/bin/setup
@@ -1,29 +1,36 @@
#!/usr/bin/env ruby
-require 'pathname'
+require 'fileutils'
+include FileUtils
# path to your application root.
-APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
+APP_ROOT = File.expand_path('..', __dir__)
-Dir.chdir APP_ROOT do
+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:
+ # Add necessary setup steps to this file.
- puts "== Installing dependencies =="
- system "gem install bundler --conservative"
- system "bundle check || bundle install"
+ 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")
- # system "cp config/database.yml.sample config/database.yml"
+ # unless File.exist?('config/database.yml')
+ # cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
- system "bin/rake db:setup"
+ system! 'bin/rails db:setup'
puts "\n== Removing old logs and tempfiles =="
- system "rm -f log/*"
- system "rm -rf tmp/cache"
+ system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
- system "touch tmp/restart.txt"
+ system! 'bin/rails restart'
end
diff --git a/myapp/config.ru b/myapp/config.ru
index 874127a3..f7ba0b52 100644
--- a/myapp/config.ru
+++ b/myapp/config.ru
@@ -1,4 +1,5 @@
# This file is used by Rack-based servers to start the application.
-require ::File.expand_path('../config/environment', __FILE__)
-run Myapp::Application
+require_relative 'config/environment'
+
+run Rails.application
diff --git a/myapp/config/application.rb b/myapp/config/application.rb
index 9797d53d..cde08fc5 100644
--- a/myapp/config/application.rb
+++ b/myapp/config/application.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../boot', __FILE__)
+require_relative 'boot'
require 'rails/all'
@@ -8,19 +8,13 @@ Bundler.require(*Rails.groups)
module Myapp
class Application < Rails::Application
+ # 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 should go into files in config/initializers
- # -- all .rb files in that directory are automatically loaded.
-
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- # config.time_zone = 'Central Time (US & Canada)'
-
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- # config.i18n.default_locale = :de
-
- # Do not swallow errors in after_commit/after_rollback callbacks.
+ # 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.
config.active_job.queue_adapter = :sidekiq
end
end
diff --git a/myapp/config/boot.rb b/myapp/config/boot.rb
index 6b750f00..30f5120d 100644
--- a/myapp/config/boot.rb
+++ b/myapp/config/boot.rb
@@ -1,3 +1,3 @@
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
diff --git a/myapp/config/database.yml b/myapp/config/database.yml
index 51a4dd45..0d02f249 100644
--- a/myapp/config/database.yml
+++ b/myapp/config/database.yml
@@ -3,23 +3,23 @@
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
-development:
+#
+default: &default
adapter: sqlite3
- database: db/development.sqlite3
- pool: 5
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
+development:
+ <<: *default
+ database: db/development.sqlite3
+
# 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:
- adapter: sqlite3
+ <<: *default
database: db/test.sqlite3
- pool: 5
- timeout: 5000
production:
- adapter: sqlite3
+ <<: *default
database: db/production.sqlite3
- pool: 5
- timeout: 5000
diff --git a/myapp/config/environment.rb b/myapp/config/environment.rb
index ee8d90dc..426333bb 100644
--- a/myapp/config/environment.rb
+++ b/myapp/config/environment.rb
@@ -1,5 +1,5 @@
# Load the Rails application.
-require File.expand_path('../application', __FILE__)
+require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize!
diff --git a/myapp/config/environments/development.rb b/myapp/config/environments/development.rb
index b55e2144..7560767f 100644
--- a/myapp/config/environments/development.rb
+++ b/myapp/config/environments/development.rb
@@ -9,33 +9,53 @@ Rails.application.configure do
# Do not eager load code on boot.
config.eager_load = false
- # Show full error reports and disable caching.
- config.consider_all_requests_local = true
- config.action_controller.perform_caching = false
+ # 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
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
- # yet still be able to expire them through the digest params.
- config.assets.digest = true
-
- # Adds additional error checking when serving assets at runtime.
- # Checks for improperly declared sprockets dependencies.
- # Raises helpful error messages.
- config.assets.raise_runtime_errors = true
+ # 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/myapp/config/environments/production.rb b/myapp/config/environments/production.rb
index aee0c866..a52e199f 100644
--- a/myapp/config/environments/production.rb
+++ b/myapp/config/environments/production.rb
@@ -14,11 +14,13 @@ Rails.application.configure do
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
- # Enable Rack::Cache to put a simple HTTP cache in front of your application
- # Add `rack-cache` to your Gemfile before enabling this.
- # For large-scale production use, consider using a caching reverse proxy like
- # NGINX, varnish or squid.
- # config.action_dispatch.rack_cache = true
+ # 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
@@ -27,16 +29,23 @@ Rails.application.configure do
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
- # yet still be able to expire them through the digest params.
- config.assets.digest = true
-
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
+ # 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
@@ -45,16 +54,16 @@ Rails.application.configure do
config.log_level = :debug
# Prepend all log lines with the following tags.
- # config.log_tags = [ :subdomain, :uuid ]
-
- # Use a different logger for distributed setups.
- # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+ config.log_tags = [ :request_id ]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
- # Enable serving of images, stylesheets, and JavaScripts from an asset server.
- # config.action_controller.asset_host = 'http://assets.example.com'
+ # 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 = "myapp_#{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.
@@ -70,6 +79,16 @@ Rails.application.configure do
# 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/myapp/config/environments/test.rb b/myapp/config/environments/test.rb
index a6c04bae..0a38fd3c 100644
--- a/myapp/config/environments/test.rb
+++ b/myapp/config/environments/test.rb
@@ -12,6 +12,12 @@ Rails.application.configure do
# 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
@@ -22,14 +28,16 @@ Rails.application.configure do
# 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
- # Randomize the order test cases are executed.
- config.active_support.test_order = :random
-
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
diff --git a/myapp/config/initializers/cookies_serializer.rb b/myapp/config/initializers/cookies_serializer.rb
index ac5f8b66..5a6a32d3 100644
--- a/myapp/config/initializers/cookies_serializer.rb
+++ b/myapp/config/initializers/cookies_serializer.rb
@@ -1,3 +1,5 @@
# Be sure to restart your server when you modify this file.
-Rails.application.config.action_dispatch.cookies_serializer = :marshal
+# 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/myapp/config/initializers/wrap_parameters.rb b/myapp/config/initializers/wrap_parameters.rb
index 33725e95..bbfc3961 100644
--- a/myapp/config/initializers/wrap_parameters.rb
+++ b/myapp/config/initializers/wrap_parameters.rb
@@ -5,10 +5,10 @@
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
- wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
+ 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
+# self.include_root_in_json = true
# end
diff --git a/myapp/config/routes.rb b/myapp/config/routes.rb
index 9cdc321e..8e2de0ce 100644
--- a/myapp/config/routes.rb
+++ b/myapp/config/routes.rb
@@ -1,4 +1,4 @@
-Myapp::Application.routes.draw do
+Rails.application.routes.draw do
mount Sidekiq::Web => '/sidekiq'
get "work" => "work#index"
get "work/email" => "work#email"