---
title:
  "Rails 7.1 returns the Active Storage attachment(s) after saving the
  attachment"
description:
  "Rails 7.1 returns the Active Storage attachment(s) after saving the
  attachment"
canonical_url: "https://www.bigbinary.com/blog/rails-7-returns-active-storage-blob-after-save"
markdown_url: "https://www.bigbinary.com/blog/rails-7-returns-active-storage-blob-after-save.md"
---

# Rails 7.1 returns the Active Storage attachment(s) after saving the attachment

Rails 7.1 returns the Active Storage attachment(s) after saving the attachment

- Author: Ghouse Mohamed
- Published: July 26, 2022
- Categories: Rails, Rails 7

Previously, saving an attachment to a record returned a boolean, indicating
whether or not the attachment was saved to the record. This is not helpful since
we have to dig into the record again to retrieve the attachment. Starting Rails
7.1, saving an attachment to a record returns the saved attachment. We can now
conveniently use blob methods like `#download`, `#url`, `#variant` etc on the
attachment without having to dig into the record again.

### Before

```ruby
# rails console
>> @user = User.create!(name: "Josh")
>> @user.avatar.attach(params[:avatar])
=> true
```

### After

```ruby
# rails console
>> @user = User.create!(name: "Josh")
>> @user.avatar.attach(params[:avatar])
=> #<ActiveStorage::Attached::One:0x00007f075e592380 @name="avatar" @record=#<User:0x00007f075e5924e8 id: "1", name: "Josh">
```

Please check out this [pull request](https://github.com/rails/rails/pull/44439)
for more details.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-7-returns-active-storage-blob-after-save)
