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

Problem implementing has_attachments #137

Open
tamlyn10 opened this issue Sep 21, 2016 · 1 comment
Open

Problem implementing has_attachments #137

tamlyn10 opened this issue Sep 21, 2016 · 1 comment

Comments

@tamlyn10
Copy link

Hi there, in my Rails 5 app, I've managed to get attachinary working well with the singular (has_attachment), however, the plural/multiple files doesn't seem to be saving to my database / working in with ActiveRecord. They ARE being uploaded to my Cloudinary account but my database has no record of them. I'm applying this to a Campaign model. Any @campaign instance I create happily returns @campaign.image, @campaign.avatar. However, @campaign.photos, returns:

pry(#<CampaignsController>)> campaign.photos**
  Attachinary::File Load (0.4ms)  SELECT "attachinary_files".* FROM "attachinary_files" WHERE "attachinary_files"."attachinariable_id" = $1 AND "attachinary_files"."attachinariable_type" = $2 AND "attachinary_files"."scope" = $3  [["attachinariable_id", 50], ["attachinariable_type", "Campaign"], ["scope", "photos"]]
=> []

despite the fact that they ARE in my params (and uploaded to Cloudinary).

pry(#<CampaignsController>)> params["campaign"]["photos"]
=> ["[{\"public_id\":\"qaggxtud1tuszez416fs\",\"version\":1474468089,\"signature\":\"3cb944ed9812d8de88c16f7438a4872a35ba0e6c\",\"width\":3264,\"height\":2448,\"format\":\"jpg\",\"resource_type\":\"image\",\"created_at\":\"2016-09-21T14:28:09Z\",\"tags\":[\"development_env\",\"attachinary_tmp\"],\"bytes\":2201871,\"type\":\"upload\",\"etag\":\"4f2fca2fe80296abd8dc17ba1a8d9129\",\"url\":\"http://res.cloudinary.com/barefootbidders/image/upload/v1474468089/qaggxtud1tuszez416fs.jpg\",\"secure_url\":\"https://res.cloudinary.com/barefootbidders/image/upload/v1474468089/qaggxtud1tuszez416fs.jpg\",\"original_filename\":\"IMG_3488\"},{\"public_id\":\"sylthqxwil4y6xvjh5mn\",\"version\":1474468112,\"signature\":\"f954c2c95a6ae06c3a87327974fc4e0f02eb49ef\",\"width\":2448,\"height\":3264,\"format\":\"jpg\",\"resource_type\":\"image\",\"created_at\":\"2016-09-21T14:28:32Z\",\"tags\":[\"development_env\",\"attachinary_tmp\"],\"bytes\":2632824,\"type\":\"upload\",\"etag\":\"5448d8c5d9fab83328cbcab079656c46\",\"url\":\"http://res.cloudinary.com/barefootbidders/image/upload/v1474468112/sylthqxwil4y6xvjh5mn.jpg\",\"secure_url\":\"https://res.cloudinary.com/barefootbidders/image/upload/v1474468112/sylthqxwil4y6xvjh5mn.jpg\",\"original_filename\":\"IMG_3490\"},{\"public_id\":\"hgfl2ykpnwnu7akiel47\",\"version\":1474468131,\"signature\":\"835c9c126d5f77bcee9e3f56b0f74834e4c2c8d7\",\"width\":2448,\"height\":3264,\"format\":\"jpg\",\"resource_type\":\"image\",\"created_at\":\"2016-09-21T14:28:51Z\",\"tags\":[\"development_env\",\"attachinary_tmp\"],\"bytes\":2260244,\"type\":\"upload\",\"etag\":\"028fd4d3169c9e1a8f0d2b984614104d\",\"url\":\"http://res.cloudinary.com/barefootbidders/image/upload/v1474468131/hgfl2ykpnwnu7akiel47.jpg\",\"secure_url\":\"https://res.cloudinary.com/barefootbidders/image/upload/v1474468131/hgfl2ykpnwnu7akiel47.jpg\",\"original_filename\":\"IMG_3491\"}]"]

Archive.zip

@PabloScolpino
Copy link

Hello,
The problem lies in the controller, the photos parameter is not properly referenced as the array it is.
You have
params.require(:campaign).permit(:question, :option_1, :option_2, :user_id, :image, :photos, :avatar).merge(user)
Whereas you should have
params.require(:campaign).permit(:question, :option_1, :option_2, :user_id, :image, photos: [], :avatar).merge(user)

I hope this helps.
Regards. P.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants