Paperclip delete attachment file
I want to delete an existing attachment without replacing it using an update action. I've only found one example of this here and could not get that to work, it just wouldn't delete and there was nothing in the logs to say why.
I wanted to do something like this on the form:. But how do I detect that checkbox and more importantly, how do I delete the image? I appreciate any help! The method declaration looks like this:. Secondly, the call to manually delete an attachment without deleting the model instance to which it is attached to is:.
And to accomplish your way of deleting the images through a checkbox, perhaps add something like this to your Page model:. This is Benoit's answer, but wrapped in a module, and covering the edge case of nested attribute models where the destroy tickbox is the only thing changed on the model.
Modified version of Paul's solution, to support Rails 5 custom attributes. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Rails Paperclip how to delete attachment? More information in the rdocs. Paperclip is aware of new attachment styles you have added in previous deploys. You can change it by:. Now you don't have to remember to refresh thumbnails in production every time you add a new style.
Unfortunately, it does not work with dynamic styles - it just ignores them. Paperclip provides rspec-compatible matchers for testing attachments. See the documentation on Paperclip::Shoulda::Matchers for more information. Because of the default path for Paperclip storage, if you try to run tests in parallel, you may find that files get overwritten because the same path is being calculated for them in each test process.
Using integration tests with FactoryBot may save multiple copies of your test files within the app. If you'd like to contribute a feature or bugfix: Thanks! Thank you to all the contributors! Paperclip is maintained and funded by thoughtbot. The names and logos for thoughtbot are trademarks of thoughtbot, inc. We love open source software! See our other projects or hire us to design, develop, and grow your product. Skip to content. Star 9. Easy file attachment management for ActiveRecord thoughtbot.
View license. Branches Tags. Could not load branches. Could not load tags. Latest commit. Link to Doorkeeper's Paperclip migration guide. Git stats 1, commits. Failed to load latest commit information. May 4, Jul 27, Remove the automatic loading of URI Adapters.
Jan 23, Bump 6. Mar 11, Increase attachment file size from int 4 bytes to bigint 8 bytes. Add Code Climate Config Aug 23, Apr 24, Aug 30, Apr 30, Update copyright notices to [ci skip].
Jan 3, May 18, Link to Colleen Schnettler's talk. Jun 7, True should not be a string. Thanks yekta — Alex Falke. Dmitriy Likhten Dmitriy Likhten 4, 6 6 gold badges 34 34 silver badges 45 45 bronze badges. Mxyk AmitA AmitA 3, 21 21 silver badges 31 31 bronze badges. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. You can send an attachment in an email to anyone with a valid email address.
System Admins for Enterprise ccounts can disable any file attachment options. See Manage Global Account Settings. Find out if this capability is included in Smartsheet Regions or Smartsheet Gov.
0コメント