8 | <% end %>
9 |
--------------------------------------------------------------------------------
/app/views/shared/_error_messages.html.erb:
--------------------------------------------------------------------------------
1 | <% if resource.errors.any? %>
2 |
3 |
4 | <%= pluralize(resource.errors.count, "error") %> prohibited this page from being saved:
5 |
6 |
7 | <% resource.errors.full_messages.each do |msg| %>
8 |
<%= msg %>
9 | <% end %>
10 |
11 |
12 | <% end %>
13 |
--------------------------------------------------------------------------------
/bin/dev:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | if command -v overmind &> /dev/null; then
4 | overmind start -f Procfile.dev "$@"
5 | else
6 | foreman start -f Procfile.dev "$@"
7 | fi
8 |
--------------------------------------------------------------------------------
/bin/docker-entrypoint:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 |
3 | # If running the rails server then create or migrate existing database
4 | if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
5 | ./bin/rails db:prepare
6 | fi
7 |
8 | exec "${@}"
9 |
--------------------------------------------------------------------------------
/bin/importmap:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require_relative "../config/application"
4 | require "importmap/commands"
5 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | APP_PATH = File.expand_path("../config/application", __dir__)
3 | require_relative "../config/boot"
4 | require "rails/commands"
5 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require_relative "../config/boot"
3 | require "rake"
4 | Rake.application.run
5 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require "fileutils"
3 |
4 | # path to your application root.
5 | APP_ROOT = File.expand_path("..", __dir__)
6 |
7 | def system!(*args)
8 | system(*args, exception: true)
9 | end
10 |
11 | FileUtils.chdir APP_ROOT do
12 | # This script is a way to set up or update your development environment automatically.
13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome.
14 | # Add necessary setup steps to this file.
15 |
16 | puts "== Installing dependencies =="
17 | system! "gem install bundler --conservative"
18 | system("bundle check") || system!("bundle install")
19 |
20 | # puts "\n== Copying sample files =="
21 | # unless File.exist?("config/database.yml")
22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml"
23 | # end
24 |
25 | puts "\n== Preparing database =="
26 | system! "bin/rails db:prepare"
27 |
28 | puts "\n== Removing old logs and tempfiles =="
29 | system! "bin/rails log:clear tmp:clear"
30 |
31 | puts "\n== Restarting application server =="
32 | system! "bin/rails restart"
33 | end
34 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # This file is used by Rack-based servers to start the application.
4 |
5 | require_relative 'config/environment'
6 |
7 | run Rails.application
8 | Rails.application.load_server
9 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require_relative 'boot'
4 |
5 | require 'rails/all'
6 |
7 | # Require the gems listed in Gemfile, including any gems
8 | # you've limited to :test, :development, or :production.
9 | Bundler.require(*Rails.groups)
10 |
11 | module ApproximatedExample
12 | class Application < Rails::Application
13 | # Initialize configuration defaults for originally generated Rails version.
14 | config.load_defaults 7.1
15 |
16 | # Please, add to the `ignore` list any other `lib` subdirectories that do
17 | # not contain `.rb` files, or that should not be reloaded or eager loaded.
18 | # Common ones are `templates`, `generators`, or `middleware`, for example.
19 | config.autoload_lib(ignore: %w[assets tasks])
20 |
21 | # Configuration for the application, engines, and railties goes here.
22 | #
23 | # These settings can be overridden in specific environments using the files
24 | # in config/environments, which are processed later.
25 | #
26 | # config.time_zone = "Central Time (US & Canada)"
27 | # config.eager_load_paths << Rails.root.join("extras")
28 | end
29 | end
30 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
4 |
5 | require 'bundler/setup' # Set up gems listed in the Gemfile.
6 | require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
7 |
--------------------------------------------------------------------------------
/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: redis
3 | url: redis://localhost:6379/1
4 |
5 | test:
6 | adapter: test
7 |
8 | production:
9 | adapter: redis
10 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
11 | channel_prefix: approximated_example_production
12 |
--------------------------------------------------------------------------------
/config/credentials.yml.enc:
--------------------------------------------------------------------------------
1 | Qq3D8zslApcSVstcb93ldwEzvKLtrhbA6CSI7NYvo7mxk6bcvHk9D1+AajZNjD1go6eZmSVUBoPbhArRynzsLxNhTfAHe4GkKJec5ob6croubEFgdrp4sk1A5Y0No3aixccyBv+KXWA1W/nq7mg20GCZsPxpCDulsr0ru3hK2Vj7IyoaBy+Hfy5CQiTDOHmwSQAVVNX2wzb+lRR1UxnumGDQ8BYtirwjBZwEwiWegoKu5l6X45xmAb+vQh37/A3Yl2Br5jsGMAF0c9424d8EsP+a0JAR2jWhB1y0dWa3bYgXD50hZuD4eBYyW0u0S247QQrTxC4Lg0EKiI1qbU+eKy0omZM6dGl4TCeI/+Zv4eZhIJgf+4R965AnIF/LZlAhLUVjGspveIV4JDO8JrcHyEiCuF33MtrZy9Pp--M9xvA63+Pro8zq20--xMqNGPkFO4p24Ck6DMHX+A==
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite. Versions 3.8.0 and up are supported.
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem "sqlite3"
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: storage/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: storage/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: storage/production.sqlite3
26 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Load the Rails application.
4 | require_relative 'application'
5 |
6 | # Initialize the Rails application.
7 | Rails.application.initialize!
8 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'active_support/core_ext/integer/time'
4 |
5 | Rails.application.configure do
6 | # Settings specified here will take precedence over those in config/application.rb.
7 |
8 | # In the development environment your application's code is reloaded any time
9 | # it changes. This slows down response time but is perfect for development
10 | # since you don't have to restart the web server when you make code changes.
11 | config.enable_reloading = true
12 |
13 | # Do not eager load code on boot.
14 | config.eager_load = false
15 |
16 | # Show full error reports.
17 | config.consider_all_requests_local = true
18 |
19 | # Enable server timing
20 | config.server_timing = true
21 |
22 | # Enable/disable caching. By default caching is disabled.
23 | # Run rails dev:cache to toggle caching.
24 | if Rails.root.join('tmp/caching-dev.txt').exist?
25 | config.action_controller.perform_caching = true
26 | config.action_controller.enable_fragment_cache_logging = true
27 |
28 | config.cache_store = :memory_store
29 | config.public_file_server.headers = {
30 | 'Cache-Control' => "public, max-age=#{2.days.to_i}"
31 | }
32 | else
33 | config.action_controller.perform_caching = false
34 |
35 | config.cache_store = :null_store
36 | end
37 |
38 | # Store uploaded files on the local file system (see config/storage.yml for options).
39 | config.active_storage.service = :local
40 |
41 | # Don't care if the mailer can't send.
42 | config.action_mailer.raise_delivery_errors = false
43 |
44 | config.action_mailer.perform_caching = false
45 |
46 | # Print deprecation notices to the Rails logger.
47 | config.active_support.deprecation = :log
48 |
49 | # Raise exceptions for disallowed deprecations.
50 | config.active_support.disallowed_deprecation = :raise
51 |
52 | # Tell Active Support which deprecation messages to disallow.
53 | config.active_support.disallowed_deprecation_warnings = []
54 |
55 | # Raise an error on page load if there are pending migrations.
56 | config.active_record.migration_error = :page_load
57 |
58 | # Highlight code that triggered database queries in logs.
59 | config.active_record.verbose_query_logs = true
60 |
61 | # Highlight code that enqueued background job in logs.
62 | config.active_job.verbose_enqueue_logs = true
63 |
64 | # Suppress logger output for asset requests.
65 | config.assets.quiet = true
66 |
67 | # Raises error for missing translations.
68 | # config.i18n.raise_on_missing_translations = true
69 |
70 | # Annotate rendered view with file names.
71 | # config.action_view.annotate_rendered_view_with_filenames = true
72 |
73 | # Uncomment if you wish to allow Action Cable access from any origin.
74 | config.action_cable.disable_request_forgery_protection = true
75 |
76 | # Raise error when a before_action's only/except options reference missing actions
77 | config.action_controller.raise_on_missing_callback_actions = true
78 |
79 | # Serve all domains.
80 | config.hosts = nil
81 | end
82 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'active_support/core_ext/integer/time'
4 |
5 | Rails.application.configure do
6 | # Settings specified here will take precedence over those in config/application.rb.
7 |
8 | # Code is not reloaded between requests.
9 | config.enable_reloading = false
10 |
11 | # Eager load code on boot. This eager loads most of Rails and
12 | # your application in memory, allowing both threaded web servers
13 | # and those relying on copy on write to perform better.
14 | # Rake tasks automatically ignore this option for performance.
15 | config.eager_load = true
16 |
17 | # Full error reports are disabled and caching is turned on.
18 | config.consider_all_requests_local = false
19 | config.action_controller.perform_caching = true
20 |
21 | # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment
22 | # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files).
23 | # config.require_master_key = true
24 |
25 | # Enable static file serving from the `/public` folder (turn off if using NGINX/Apache for it).
26 | config.public_file_server.enabled = true
27 |
28 | # Compress CSS using a preprocessor.
29 | # config.assets.css_compressor = :sass
30 |
31 | # Do not fallback to assets pipeline if a precompiled asset is missed.
32 | config.assets.compile = false
33 |
34 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
35 | # config.asset_host = "http://assets.example.com"
36 |
37 | # Specifies the header that your server uses for sending files.
38 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
39 | # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
40 |
41 | # Store uploaded files on the local file system (see config/storage.yml for options).
42 | config.active_storage.service = :local
43 |
44 | # Mount Action Cable outside main process or domain.
45 | # config.action_cable.mount_path = nil
46 | # config.action_cable.url = "wss://example.com/cable"
47 | # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
48 |
49 | # Assume all access to the app is happening through a SSL-terminating reverse proxy.
50 | # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
51 | # config.assume_ssl = true
52 |
53 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
54 | config.force_ssl = true
55 |
56 | # Log to STDOUT by default
57 | config.logger = ActiveSupport::Logger.new($stdout)
58 | .tap { |logger| logger.formatter = Logger::Formatter.new }
59 | .then { |logger| ActiveSupport::TaggedLogging.new(logger) }
60 |
61 | # Prepend all log lines with the following tags.
62 | config.log_tags = [:request_id]
63 |
64 | # Info include generic and useful information about system operation, but avoids logging too much
65 | # information to avoid inadvertent exposure of personally identifiable information (PII). If you
66 | # want to log everything, set the level to "debug".
67 | config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')
68 |
69 | # Use a different cache store in production.
70 | # config.cache_store = :mem_cache_store
71 |
72 | # Use a real queuing backend for Active Job (and separate queues per environment).
73 | # config.active_job.queue_adapter = :resque
74 | # config.active_job.queue_name_prefix = "approximated_example_production"
75 |
76 | config.action_mailer.perform_caching = false
77 |
78 | # Ignore bad email addresses and do not raise email delivery errors.
79 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
80 | # config.action_mailer.raise_delivery_errors = false
81 |
82 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
83 | # the I18n.default_locale when a translation cannot be found).
84 | config.i18n.fallbacks = true
85 |
86 | # Don't log any deprecations.
87 | config.active_support.report_deprecations = false
88 |
89 | # Do not dump schema after migrations.
90 | config.active_record.dump_schema_after_migration = false
91 |
92 | # Enable DNS rebinding protection and other `Host` header attacks.
93 | # config.hosts = [
94 | # "example.com", # Allow requests from example.com
95 | # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
96 | # ]
97 | # Skip DNS rebinding protection for the default health check endpoint.
98 | # config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
99 | end
100 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'active_support/core_ext/integer/time'
4 |
5 | # The test environment is used exclusively to run your application's
6 | # test suite. You never need to work with it otherwise. Remember that
7 | # your test database is "scratch space" for the test suite and is wiped
8 | # and recreated between test runs. Don't rely on the data there!
9 |
10 | Rails.application.configure do
11 | # Settings specified here will take precedence over those in config/application.rb.
12 |
13 | # While tests run files are not watched, reloading is not necessary.
14 | config.enable_reloading = false
15 |
16 | # Eager loading loads your entire application. When running a single test locally,
17 | # this is usually not necessary, and can slow down your test suite. However, it's
18 | # recommended that you enable it in continuous integration systems to ensure eager
19 | # loading is working properly before deploying your code.
20 | config.eager_load = ENV['CI'].present?
21 |
22 | # Configure public file server for tests with Cache-Control for performance.
23 | config.public_file_server.enabled = true
24 | config.public_file_server.headers = {
25 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
26 | }
27 |
28 | # Show full error reports and disable caching.
29 | config.consider_all_requests_local = true
30 | config.action_controller.perform_caching = false
31 | config.cache_store = :null_store
32 |
33 | # Raise exceptions instead of rendering exception templates.
34 | config.action_dispatch.show_exceptions = :rescuable
35 |
36 | # Disable request forgery protection in test environment.
37 | config.action_controller.allow_forgery_protection = false
38 |
39 | # Store uploaded files on the local file system in a temporary directory.
40 | config.active_storage.service = :test
41 |
42 | config.action_mailer.perform_caching = false
43 |
44 | # Tell Action Mailer not to deliver emails to the real world.
45 | # The :test delivery method accumulates sent emails in the
46 | # ActionMailer::Base.deliveries array.
47 | config.action_mailer.delivery_method = :test
48 |
49 | # Print deprecation notices to the stderr.
50 | config.active_support.deprecation = :stderr
51 |
52 | # Raise exceptions for disallowed deprecations.
53 | config.active_support.disallowed_deprecation = :raise
54 |
55 | # Tell Active Support which deprecation messages to disallow.
56 | config.active_support.disallowed_deprecation_warnings = []
57 |
58 | # Raises error for missing translations.
59 | # config.i18n.raise_on_missing_translations = true
60 |
61 | # Annotate rendered view with file names.
62 | # config.action_view.annotate_rendered_view_with_filenames = true
63 |
64 | # Raise error when a before_action's only/except options reference missing actions
65 | config.action_controller.raise_on_missing_callback_actions = true
66 | end
67 |
--------------------------------------------------------------------------------
/config/importmap.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Pin npm packages by running ./bin/importmap
4 |
5 | pin 'application', preload: true
6 | pin '@hotwired/turbo-rails', to: 'turbo.min.js', preload: true
7 | pin '@hotwired/stimulus', to: 'stimulus.min.js', preload: true
8 | pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js', preload: true
9 | pin_all_from 'app/javascript/controllers', under: 'controllers'
10 | pin 'autosize', to: 'https://ga.jspm.io/npm:autosize@6.0.1/dist/autosize.esm.js'
11 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # Version of your assets, change this if you want to expire all your assets.
6 | Rails.application.config.assets.version = '1.0'
7 |
8 | # Add additional assets to the asset load path.
9 | # Rails.application.config.assets.paths << Emoji.images_path
10 |
11 | # Precompile additional assets.
12 | # application.js, application.css, and all non-JS/CSS in the app/assets
13 | # folder are already added.
14 | # Rails.application.config.assets.precompile += %w( admin.js admin.css )
15 |
--------------------------------------------------------------------------------
/config/initializers/content_security_policy.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # Define an application-wide content security policy.
6 | # See the Securing Rails Applications Guide for more information:
7 | # https://guides.rubyonrails.org/security.html#content-security-policy-header
8 |
9 | # Rails.application.configure do
10 | # config.content_security_policy do |policy|
11 | # policy.default_src :self, :https
12 | # policy.font_src :self, :https, :data
13 | # policy.img_src :self, :https, :data
14 | # policy.object_src :none
15 | # policy.script_src :self, :https
16 | # policy.style_src :self, :https
17 | # # Specify URI for violation reports
18 | # # policy.report_uri "/csp-violation-report-endpoint"
19 | # end
20 | #
21 | # # Generate session nonces for permitted importmap, inline scripts, and inline styles.
22 | # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
23 | # config.content_security_policy_nonce_directives = %w(script-src style-src)
24 | #
25 | # # Report violations without enforcing the policy.
26 | # # config.content_security_policy_report_only = true
27 | # end
28 |
--------------------------------------------------------------------------------
/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.
6 | # Use this to limit dissemination of sensitive information.
7 | # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
8 | Rails.application.config.filter_parameters += %i[
9 | passw secret token _key crypt salt certificate otp ssn
10 | ]
11 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # Add new inflection rules using the following format. Inflections
6 | # are locale specific, and you may define rules for as many different
7 | # locales as you wish. All of these examples are active by default:
8 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
9 | # inflect.plural /^(ox)$/i, "\\1en"
10 | # inflect.singular /^(ox)en/i, "\\1"
11 | # inflect.irregular "person", "people"
12 | # inflect.uncountable %w( fish sheep )
13 | # end
14 |
15 | # These inflection rules are supported but not enabled by default:
16 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
17 | # inflect.acronym "RESTful"
18 | # end
19 |
--------------------------------------------------------------------------------
/config/initializers/permissions_policy.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # Be sure to restart your server when you modify this file.
4 |
5 | # Define an application-wide HTTP permissions policy. For further
6 | # information see: https://developers.google.com/web/updates/2018/06/feature-policy
7 |
8 | # Rails.application.config.permissions_policy do |policy|
9 | # policy.camera :none
10 | # policy.gyroscope :none
11 | # policy.microphone :none
12 | # policy.usb :none
13 | # policy.fullscreen :self
14 | # policy.payment :self, "https://secure.example.com"
15 | # end
16 |
--------------------------------------------------------------------------------
/config/initializers/public_suffix.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | if Rails.env.development?
4 | # Allow test domain in development env
5 | PublicSuffix::List.default << PublicSuffix::Rule.factory('test')
6 | end
7 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization and
2 | # are automatically loaded by Rails. If you want to use locales other than
3 | # English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t "hello"
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t("hello") %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more about the API, please read the Rails Internationalization guide
20 | # at https://guides.rubyonrails.org/i18n.html.
21 | #
22 | # Be aware that YAML interprets the following case-insensitive strings as
23 | # booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings
24 | # must be quoted to be interpreted as strings. For example:
25 | #
26 | # en:
27 | # "yes": yup
28 | # enabled: "ON"
29 |
30 | en:
31 | hello: "Hello world"
32 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # This configuration file will be evaluated by Puma. The top-level methods that
4 | # are invoked here are part of Puma's configuration DSL. For more information
5 | # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
6 |
7 | # Puma can serve each request in a thread from an internal thread pool.
8 | # The `threads` method setting takes two numbers: a minimum and maximum.
9 | # Any libraries that use thread pools should be configured to match
10 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
11 | # and maximum; this matches the default thread size of Active Record.
12 | max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
13 | min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
14 | threads min_threads_count, max_threads_count
15 |
16 | # Specifies that the worker count should equal the number of processors in production.
17 | if ENV['RAILS_ENV'] == 'production'
18 | require 'concurrent-ruby'
19 | worker_count = Integer(ENV.fetch('WEB_CONCURRENCY') { Concurrent.physical_processor_count })
20 | workers worker_count if worker_count > 1
21 | end
22 |
23 | # Specifies the `worker_timeout` threshold that Puma will use to wait before
24 | # terminating a worker in development environments.
25 | worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'
26 |
27 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
28 | port ENV.fetch('PORT', 3000)
29 |
30 | # Specifies the `environment` that Puma will run in.
31 | environment ENV.fetch('RAILS_ENV', 'development')
32 |
33 | # Specifies the `pidfile` that Puma will use.
34 | pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')
35 |
36 | # Allow puma to be restarted by `bin/rails restart` command.
37 | plugin :tmp_restart
38 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | Rails.application.routes.draw do
4 | constraints AppDomainConstraint do
5 | root 'pages#index', as: :pages_root
6 | resources :pages, except: %i[index]
7 | end
8 |
9 | constraints !AppDomainConstraint do
10 | root 'public_pages#show', as: :public_pages_root
11 | end
12 |
13 | get 'up' => 'rails/health#show', as: :rails_health_check
14 | end
15 |
--------------------------------------------------------------------------------
/config/storage.yml:
--------------------------------------------------------------------------------
1 | test:
2 | service: Disk
3 | root: <%= Rails.root.join("tmp/storage") %>
4 |
5 | local:
6 | service: Disk
7 | root: <%= Rails.root.join("storage") %>
8 |
9 | # Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10 | # amazon:
11 | # service: S3
12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14 | # region: us-east-1
15 | # bucket: your_own_bucket-<%= Rails.env %>
16 |
17 | # Remember not to checkin your GCS keyfile to a repository
18 | # google:
19 | # service: GCS
20 | # project: your_project
21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22 | # bucket: your_own_bucket-<%= Rails.env %>
23 |
24 | # Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25 | # microsoft:
26 | # service: AzureStorage
27 | # storage_account_name: your_account_name
28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29 | # container: your_container_name-<%= Rails.env %>
30 |
31 | # mirror:
32 | # service: Mirror
33 | # primary: local
34 | # mirrors: [ amazon, google, microsoft ]
35 |
--------------------------------------------------------------------------------
/config/tailwind.config.js:
--------------------------------------------------------------------------------
1 | const defaultTheme = require('tailwindcss/defaultTheme')
2 |
3 | module.exports = {
4 | content: [
5 | './app/helpers/**/*.rb',
6 | './app/javascript/**/*.js',
7 | './app/views/**/*.html.erb'
8 | ],
9 |
10 | theme: {
11 | extend: {
12 | fontFamily: {
13 | sans: ['Inter var', ...defaultTheme.fontFamily.sans],
14 | },
15 | },
16 | },
17 |
18 | plugins: [
19 | require('@tailwindcss/forms'),
20 | require('@tailwindcss/typography'),
21 | ]
22 | }
23 |
--------------------------------------------------------------------------------
/db/migrate/20230721090602_create_pages.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class CreatePages < ActiveRecord::Migration[7.0]
4 | def change
5 | create_table :pages do |t|
6 | t.string :title, null: false
7 | t.text :content, null: false
8 | t.string :domain, null: false
9 |
10 | t.timestamps
11 |
12 | t.index :domain, unique: true
13 | end
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # This file is auto-generated from the current state of the database. Instead
2 | # of editing this file, please use the migrations feature of Active Record to
3 | # incrementally modify your database, and then regenerate this schema definition.
4 | #
5 | # This file is the source Rails uses to define your schema when running `bin/rails
6 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7 | # be faster and is potentially less error prone than running all of your
8 | # migrations from scratch. Old migrations may fail to apply correctly if those
9 | # migrations use external dependencies or application code.
10 | #
11 | # It's strongly recommended that you check this file into your version control system.
12 |
13 | ActiveRecord::Schema[7.1].define(version: 2023_07_21_090602) do
14 | create_table "pages", force: :cascade do |t|
15 | t.string "title", null: false
16 | t.text "content", null: false
17 | t.string "domain", null: false
18 | t.datetime "created_at", null: false
19 | t.datetime "updated_at", null: false
20 | t.index ["domain"], name: "index_pages_on_domain", unique: true
21 | end
22 |
23 | end
24 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | # This file should ensure the existence of records required to run the application in every environment (production,
4 | # development, test). The code here should be idempotent so that it can be executed at any point in every environment.
5 | # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
6 | #
7 | # Example:
8 | #
9 | # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
10 | # MovieGenre.find_or_create_by!(name: genre_name)
11 | # end
12 |
--------------------------------------------------------------------------------
/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Approximated-Inc/rails-custom-domains-example/8dc647ad934c4102905c9e3a11476bc1b38134c8/lib/assets/.keep
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Approximated-Inc/rails-custom-domains-example/8dc647ad934c4102905c9e3a11476bc1b38134c8/lib/tasks/.keep
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Approximated-Inc/rails-custom-domains-example/8dc647ad934c4102905c9e3a11476bc1b38134c8/log/.keep
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.