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

Empty file field deletes previously attached files when updating a record that has active_storage #3520

Closed
Shpigford opened this issue May 19, 2022 · 3 comments

Comments

@Shpigford
Copy link

Shpigford commented May 19, 2022

I have a vanilla Art model with has_many_attached in it...

class Art < ApplicationRecord
  has_many_attached :images
  belongs_to :art_category
end

This appropriately adds an "Images" field in rails_admin, and when creating a new record, it works perfectly.

CleanShot 2022-05-19 at 16 04 24@2x

However, if I return to that record and update any other field (but don't touch the images), it deletes the associated image.

Parameters: {
  "authenticity_token"=>"[FILTERED]", 
  "art"=>{
    "name"=>"mountains", 
    "description"=>"this is a description i'm writing", 
    "tools"=>"midjourney, photoshop, wombo", 
    "nft"=>"1", 
    "external_link"=>"https://opensea.io/...", 
    "art_category_id"=>"1", 
    "images"=>[""]
  }, 
  "return_to"=>"http://localhost:3000/admin/art_category/new", 
  "_add_edit"=>"true", 
  "model_name"=>"art", 
  "id"=>"6"
}

As you can see, the images field is submitting a blank array.

Is this a setting I'm missing? Or is this a bug?

Additional context

  • rails version: 7.0.3
  • rails_admin version: 3.0.0
@darrenterhune
Copy link
Contributor

I'm on latest stable rails 6.0 and rails_admin 3.0.0 and don't have this issue. We do however follow this https://github.com/railsadminteam/rails_admin/wiki/ActiveStorage#deleting-an-attachment but that shouldn't affect what you're seeing afaict

@mshibuya
Copy link
Member

Thanks for reporting. This is because of those changes in ActiveStorage.
rails/rails@4f191b9
rails/rails@400b210
Pushed the fix into the master branch, so please try it when you get a chance.

@aliceclv
Copy link

aliceclv commented Nov 7, 2023

I'm still experiencing that issue.
Pictures and videos attached are sent as an empty array.
Here are the parameters sent on update, the issue is only happening on production though. I'm using rails 7.1.1 and rails_admin: 3.1.2

 {"authenticity_token"=>"[FILTERED]", "seller_item"=>{"seller_id"=>"xxx", "featured"=>"1", "title"=>"", "description"=>"", "pictures"=>[""], "videos"=>[""]}, "return_to"=>"xxxxx", "_save"=>"", "model_name"=>"seller_item", "id"=>"xxxx"}

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

4 participants