diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-08-04 18:05:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-04 18:05:13 -0500 |
commit | 552840660389e39f3ba8e47dcf35ab817c01cb48 (patch) | |
tree | 5013b2d5a1691ac1f675935eea38848639ac54bc /railties/lib | |
parent | 978b3d604ab082ac0be071245646b0803b8ff382 (diff) | |
parent | 3179f089be4f631b9c0f8b431567992164f2bdb4 (diff) | |
download | rails-552840660389e39f3ba8e47dcf35ab817c01cb48.tar.gz rails-552840660389e39f3ba8e47dcf35ab817c01cb48.tar.bz2 rails-552840660389e39f3ba8e47dcf35ab817c01cb48.zip |
Merge pull request #30020 from rails/active-storage-import
Add Active Storage to Rails
Diffstat (limited to 'railties/lib')
11 files changed, 71 insertions, 3 deletions
diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb index 7606ea0e46..913bcf4120 100644 --- a/railties/lib/rails/all.rb +++ b/railties/lib/rails/all.rb @@ -7,6 +7,7 @@ require "rails" action_mailer/railtie active_job/railtie action_cable/engine + active_storage/engine rails/test_unit/railtie sprockets/railtie ).each do |railtie| diff --git a/railties/lib/rails/api/task.rb b/railties/lib/rails/api/task.rb index 49267c2329..195048a98b 100644 --- a/railties/lib/rails/api/task.rb +++ b/railties/lib/rails/api/task.rb @@ -64,6 +64,13 @@ module Rails ) }, + "activestorage" => { + include: %w( + README.md + lib/active_storage/**/*.rb + ) + }, + "railties" => { include: %w( README.rdoc diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 507099ef57..cbe68823d4 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -113,6 +113,7 @@ module Rails template "cable.yml" unless options[:skip_action_cable] template "puma.rb" unless options[:skip_puma] template "spring.rb" if spring_install? + template "storage.yml" directory "environments" directory "initializers" @@ -122,9 +123,10 @@ module Rails def config_when_updating cookie_serializer_config_exist = File.exist?("config/initializers/cookies_serializer.rb") - action_cable_config_exist = File.exist?("config/cable.yml") - rack_cors_config_exist = File.exist?("config/initializers/cors.rb") - assets_config_exist = File.exist?("config/initializers/assets.rb") + action_cable_config_exist = File.exist?("config/cable.yml") + active_storage_config_exist = File.exist?("config/storage.yml") + rack_cors_config_exist = File.exist?("config/initializers/cors.rb") + assets_config_exist = File.exist?("config/initializers/assets.rb") config @@ -136,6 +138,10 @@ module Rails template "config/cable.yml" end + if !active_storage_config_exist + template "config/storage.yml" + end + unless rack_cors_config_exist remove_file "config/initializers/cors.rb" end @@ -173,6 +179,11 @@ module Rails directory "public", "public", recursive: false end + def storage + empty_directory_with_keep_file "storage" + empty_directory_with_keep_file "tmp/storage" + end + def test empty_directory_with_keep_file "test/fixtures" empty_directory_with_keep_file "test/fixtures/files" diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt index 4206002a1b..62fd04f113 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt @@ -12,6 +12,7 @@ // <% unless options[:skip_javascript] -%> //= require rails-ujs +//= require activestorage <% unless options[:skip_turbolinks] -%> //= require turbolinks <% end -%> diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 0b1d22228e..9931709d7b 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -11,6 +11,7 @@ require "active_job/railtie" require "action_controller/railtie" <%= comment_if :skip_action_mailer %>require "action_mailer/railtie" require "action_view/railtie" +require "active_storage/engine" <%= comment_if :skip_action_cable %>require "action_cable/engine" <%= comment_if :skip_sprockets %>require "sprockets/railtie" <%= comment_if :skip_test %>require "rails/test_unit/railtie" diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index b75b65c8df..d69769f631 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -26,6 +26,9 @@ Rails.application.configure do 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 <%- unless options.skip_action_mailer? -%> # Don't care if the mailer can't send. diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index d44331a888..5b16ada442 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -45,6 +45,8 @@ Rails.application.configure do # 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 <%- unless options[:skip_action_cable] -%> # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index 56416b3075..fdf16b4730 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -27,6 +27,9 @@ 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 <%- unless options.skip_action_mailer? -%> config.action_mailer.perform_caching = false diff --git a/railties/lib/rails/generators/rails/app/templates/config/storage.yml b/railties/lib/rails/generators/rails/app/templates/config/storage.yml new file mode 100644 index 0000000000..522048701c --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/config/storage.yml @@ -0,0 +1,35 @@ +test: + service: Disk + root: <%%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%%= Rails.root.join("storage") %> + +# Use rails secrets:edit to set the AWS secrets (as shared:aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%%= Rails.application.secrets.dig(:aws, :access_key_id) %> +# secret_access_key: <%%= Rails.application.secrets.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# keyfile: <%%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails secrets:edit to set the Azure secret (as shared:azure:storage_access_key) +# microsoft: +# service: Azure +# path: your_azure_storage_path +# storage_account_name: your_account_name +# storage_access_key: <%%= Rails.application.secrets.dig(:azure, :secret_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index 1e6b9afcd2..64ed09dc4b 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -21,6 +21,9 @@ !/tmp/.keep <% end -%> +# Ignore uploaded files in development +/storage/* + <% unless options[:skip_yarn] -%> /node_modules /yarn-error.log diff --git a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb index d03b1be878..5e0cfd6c21 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb +++ b/railties/lib/rails/generators/rails/plugin/templates/rails/application.rb @@ -9,6 +9,7 @@ require "action_controller/railtie" require "action_view/railtie" <%= comment_if :skip_action_mailer %>require "action_mailer/railtie" require "active_job/railtie" +require "active_storage/engine" <%= comment_if :skip_action_cable %>require "action_cable/engine" <%= comment_if :skip_test %>require "rails/test_unit/railtie" <%= comment_if :skip_sprockets %>require "sprockets/railtie" |