mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
[ci skip] clarify rails 6 for AS :attachment
The current guides appear to indicate that the :attachment and
:attachments field generators can be used with any version of Active
Storage, however they were added in ecdcf06
, which was first included in
Rails 6.0.
This updates the docs to indicate that Rails 6 is necessary to use those
fields in model generators.
This commit is contained in:
parent
33293c577b
commit
802f855710
1 changed files with 14 additions and 14 deletions
|
@ -321,13 +321,7 @@ The [`has_one_attached`][] macro sets up a one-to-one mapping between records an
|
||||||
files. Each record can have one file attached to it.
|
files. Each record can have one file attached to it.
|
||||||
|
|
||||||
For example, suppose your application has a `User` model. If you want each user to
|
For example, suppose your application has a `User` model. If you want each user to
|
||||||
have an avatar, run a model generator command as follows:
|
have an avatar, define the `User` model as follows:
|
||||||
|
|
||||||
```ruby
|
|
||||||
bin/rails generate model User avatar:attachment
|
|
||||||
```
|
|
||||||
|
|
||||||
or define the `User` model like this
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class User < ApplicationRecord
|
class User < ApplicationRecord
|
||||||
|
@ -335,6 +329,12 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or if you are using Rails 6.0+, you can run a model generator command like this:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
bin/rails generate model User avatar:attachment
|
||||||
|
```
|
||||||
|
|
||||||
You can create a user with an avatar:
|
You can create a user with an avatar:
|
||||||
|
|
||||||
```erb
|
```erb
|
||||||
|
@ -403,13 +403,7 @@ The [`has_many_attached`][] macro sets up a one-to-many relationship between rec
|
||||||
and files. Each record can have many files attached to it.
|
and files. Each record can have many files attached to it.
|
||||||
|
|
||||||
For example, suppose your application has a `Message` model. If you want each
|
For example, suppose your application has a `Message` model. If you want each
|
||||||
message to have many images, run a model generator command as follows:
|
message to have many images, define the `Message` model as follows:
|
||||||
|
|
||||||
```ruby
|
|
||||||
bin/rails generate model Message images:attachments
|
|
||||||
```
|
|
||||||
|
|
||||||
or define the `Message` model like this:
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class Message < ApplicationRecord
|
class Message < ApplicationRecord
|
||||||
|
@ -417,6 +411,12 @@ class Message < ApplicationRecord
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or if you are using Rails 6.0+, you can run a model generator command like this:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
bin/rails generate model Message images:attachments
|
||||||
|
```
|
||||||
|
|
||||||
You can create a message with images:
|
You can create a message with images:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
|
Loading…
Reference in a new issue