Skip to content

Commit

Permalink
Merge pull request #46599 from shouichi/improve-active-storage-guide
Browse files Browse the repository at this point in the history
Describe env specific ActiveStorage config in the AS guide [skip ci]
  • Loading branch information
zzak committed Jan 7, 2023
2 parents 6494c87 + 15b3420 commit 131307e
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions guides/source/active_storage_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ To use the test service when testing, you add the following to
config.active_storage.service = :test
```

Continue reading for more information on the built-in service adapters (e.g.
`Disk` and `S3`) and the configuration they require.

NOTE: Configuration files that are environment-specific will take precedence:
in production, for example, the `config/storage/production.yml` file (if existent)
will take precedence over the `config/storage.yml` file.
Expand All @@ -139,6 +136,9 @@ azure:
container: your_container_name-<%= Rails.env %>
```

Continue reading for more information on the built-in service adapters (e.g.
`Disk` and `S3`) and the configuration they require.

### Disk Service

Declare a Disk service in `config/storage.yml`:
Expand Down Expand Up @@ -1415,6 +1415,33 @@ end
[fixtures]: testing.html#the-low-down-on-fixtures
[`ActiveStorage::FixtureSet`]: https://api.rubyonrails.org/classes/ActiveStorage/FixtureSet.html

### Configuring services

You can add `config/storage/test.yml` to configure services to be used in test environment
This is useful when the `service` option is used.

```ruby
class User < ApplicationRecord
has_one_attached :avatar, service: :s3
end
```

Without `config/storage/test.yml`, the `s3` service configured in `config/storage.yml` is used - even when running tests.

The default configuration would be used and files would be uploaded to the service provider configured in `config/storage.yml`.

In this case, you can add `config/storage/test.yml` and use Disk service for `s3` service to prevent sending requests.

```yaml
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>

s3:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
```

Implementing Support for Other Cloud Services
---------------------------------------------

Expand Down

0 comments on commit 131307e

Please sign in to comment.