Use config/storage.yml as part of the skeleton and loading

上级 54663f55
...@@ -91,7 +91,7 @@ Variation of image attachment: ...@@ -91,7 +91,7 @@ Variation of image attachment:
2. Add `require "active_storage"` to config/application.rb, after `require "rails/all"` line. 2. Add `require "active_storage"` to config/application.rb, after `require "rails/all"` line.
3. Run `rails activestorage:install` to create needed directories, migrations, and configuration. 3. Run `rails activestorage:install` to create needed directories, migrations, and configuration.
4. Configure the storage service in `config/environments/*` with `config.active_storage.service = :local` 4. Configure the storage service in `config/environments/*` with `config.active_storage.service = :local`
that references the services configured in `config/storage_services.yml`. that references the services configured in `config/storage.yml`.
5. Optional: Add `gem "aws-sdk", "~> 2"` to your Gemfile if you want to use AWS S3. 5. Optional: Add `gem "aws-sdk", "~> 2"` to your Gemfile if you want to use AWS S3.
6. Optional: Add `gem "google-cloud-storage", "~> 1.3"` to your Gemfile if you want to use Google Cloud Storage. 6. Optional: Add `gem "google-cloud-storage", "~> 1.3"` to your Gemfile if you want to use Google Cloud Storage.
7. Optional: Add `gem "mini_magick"` to your Gemfile if you want to use variants. 7. Optional: Add `gem "mini_magick"` to your Gemfile if you want to use variants.
......
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
microsoft:
service: Azure
path: your_azure_storage_path
storage_account_name: your_account_name
storage_access_key: <%= Rails.application.secrets.azure[:secret_access_key] %>
container: your_container_name
mirror:
service: Mirror
primary: local
mirrors: [ amazon, google ]
...@@ -31,7 +31,7 @@ class Engine < Rails::Engine # :nodoc: ...@@ -31,7 +31,7 @@ class Engine < Rails::Engine # :nodoc:
initializer "active_storage.services" do initializer "active_storage.services" do
config.after_initialize do |app| config.after_initialize do |app|
if config_choice = app.config.active_storage.service if config_choice = app.config.active_storage.service
config_file = Pathname.new(Rails.root.join("config/storage_services.yml")) config_file = Pathname.new(Rails.root.join("config/storage.yml"))
raise("Couldn't find Active Storage configuration in #{config_file}") unless config_file.exist? raise("Couldn't find Active Storage configuration in #{config_file}") unless config_file.exist?
require "yaml" require "yaml"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# * +Mirror+, to be able to use several services to manage attachments. # * +Mirror+, to be able to use several services to manage attachments.
# #
# Inside a Rails application, you can set-up your services through the # Inside a Rails application, you can set-up your services through the
# generated <tt>config/storage_services.yml</tt> file and reference one # generated <tt>config/storage.yml</tt> file and reference one
# of the aforementioned constant under the +service+ key. For example: # of the aforementioned constant under the +service+ key. For example:
# #
# local: # local:
......
...@@ -122,9 +122,10 @@ def config ...@@ -122,9 +122,10 @@ def config
def config_when_updating def config_when_updating
cookie_serializer_config_exist = File.exist?("config/initializers/cookies_serializer.rb") cookie_serializer_config_exist = File.exist?("config/initializers/cookies_serializer.rb")
action_cable_config_exist = File.exist?("config/cable.yml") action_cable_config_exist = File.exist?("config/cable.yml")
rack_cors_config_exist = File.exist?("config/initializers/cors.rb") active_storage_config_exist = File.exist?("config/storage.yml")
assets_config_exist = File.exist?("config/initializers/assets.rb") rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
assets_config_exist = File.exist?("config/initializers/assets.rb")
config config
...@@ -136,6 +137,10 @@ def config_when_updating ...@@ -136,6 +137,10 @@ def config_when_updating
template "config/cable.yml" template "config/cable.yml"
end end
if !active_storage_config_exist
template "config/storage.yml"
end
unless rack_cors_config_exist unless rack_cors_config_exist
remove_file "config/initializers/cors.rb" remove_file "config/initializers/cors.rb"
end end
......
...@@ -27,7 +27,7 @@ Rails.application.configure do ...@@ -27,7 +27,7 @@ Rails.application.configure do
config.cache_store = :null_store config.cache_store = :null_store
end end
# Store uploaded files on the local file system (see config/storage_services.yml for options) # Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local config.active_storage.service = :local
<%- unless options.skip_action_mailer? -%> <%- unless options.skip_action_mailer? -%>
......
...@@ -45,7 +45,7 @@ Rails.application.configure do ...@@ -45,7 +45,7 @@ Rails.application.configure do
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Store uploaded files on the local file system (see config/storage_services.yml for options) # Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local config.active_storage.service = :local
<%- unless options[:skip_action_cable] -%> <%- unless options[:skip_action_cable] -%>
# Mount Action Cable outside main process or domain # Mount Action Cable outside main process or domain
......
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
# 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 ]
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
config/routes.rb config/routes.rb
config/secrets.yml config/secrets.yml
config/spring.rb config/spring.rb
config/storage_services.yml config/storage.yml
db db
db/seeds.rb db/seeds.rb
lib lib
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册