Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result of ActiveStorage #attach is different from 5.2.3 to 6.0 and is not documented #36238

Closed
weilandia opened this issue May 10, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@weilandia
Copy link
Contributor

commented May 10, 2019

Steps to reproduce

Run the tests in the following app and then change the Rails version to 5.2.3 and run the tests again.

https://github.com/weilandia/active-storage-attach-change

Expected behavior

In 5.2.3, #attach returns the array of attachments, while in 6.0 it returns true. I'm guessing it has to do with https://github.com/rails/rails/pull/33303/files#diff-60af6faf13016eb62a7885e5eecd9b34 but I'm not sure if it is intended.

If it is intended, should we document the change? Is there a suggested way to get the attachment objects after calling #attach? i.e. to accomplish something similar to:

file = user.files.attach(params[:signed_id])[0]

System configuration

Rails version:
6.0.0rc1
Ruby version:
2.6.2

@georgeclaghorn

This comment has been minimized.

Copy link
Member

commented May 11, 2019

#attach has never been documented as returning anything, which means you ought not rely on its return value.

Is there a suggested way to get the attachment objects after calling #attach? i.e. to accomplish something similar to:

user.files.first and user.files[0] should both work after calling #attach.

@weilandia weilandia closed this May 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.