Rails Paperclip, Deleting Attachment with default_url option doesn't change attachment url The Next CEO of Stack OverflowDelete an image with Papercliprails paperclip .destroy & .clear removes the file from s3, but .url is still directing to s3 instead of default_urlHow do I get the current absolute URL in Ruby on Rails?Rails and paperclip, delete the record but don't delete the attachmentRails 3, windows, Paperclip can't make thumbnailsTrying to add the Paperclip gem to rails projectpaperclip not deleting attachmentcreate different styled image attachments with paperclip based on polymorphic model attribute?Attach image in form from a url with Paperclip (Rails)Rails and Paperclip storing images in a specific path sets wrong URLAvatar has contents that are not what they are reported to beUsing Paperclip to upload images within a json attribute in a model in Rails 5

Return the Closest Prime Number

Why don't programming languages automatically manage the synchronous/asynchronous problem?

What happened in Rome, when the western empire "fell"?

What is "(CFMCC)" on an ILS approach chart?

How to safely derail a train during transit?

Interfacing a button to MCU (and PC) with 50m long cable

What connection does MS Office have to Netscape Navigator?

Rotate a column

Complex fractions

How does the Z80 determine which peripheral sent an interrupt?

Why do airplanes bank sharply to the right after air-to-air refueling?

How to count occurrences of text in a file?

How long to clear the 'suck zone' of a turbofan after start is initiated?

What does "Its cash flow is deeply negative" mean?

Is micro rebar a better way to reinforce concrete than rebar?

Is there a way to save my career from absolute disaster?

Why does the UK parliament need a vote on the political declaration?

If the heap is zero-initialized for security, then why is the stack merely uninitialized?

Sending manuscript to multiple publishers

Solidity! Invalid implicit conversion from string memory to bytes memory requested

Unreliable Magic - Is it worth it?

What flight has the highest ratio of time difference to flight time?

Several mode to write the symbol of a vector

Indicator light circuit



Rails Paperclip, Deleting Attachment with default_url option doesn't change attachment url



The Next CEO of Stack OverflowDelete an image with Papercliprails paperclip .destroy & .clear removes the file from s3, but .url is still directing to s3 instead of default_urlHow do I get the current absolute URL in Ruby on Rails?Rails and paperclip, delete the record but don't delete the attachmentRails 3, windows, Paperclip can't make thumbnailsTrying to add the Paperclip gem to rails projectpaperclip not deleting attachmentcreate different styled image attachments with paperclip based on polymorphic model attribute?Attach image in form from a url with Paperclip (Rails)Rails and Paperclip storing images in a specific path sets wrong URLAvatar has contents that are not what they are reported to beUsing Paperclip to upload images within a json attribute in a model in Rails 5










3















My user model has avatar attachment



class User
has_attached_file :avatar, styles: medium: '300x300#', thumb: '150x150#' , default_url: :default_url_by_gender

def default_url_by_gender
if female?
'female.svg'
else
'male.svg'
end
end
end


Before uploading an image the avatar.url return default url, when I upload an image and save then delete it, the avatar.url still direct to the deleted image url not the default_url



I delete the avatar with following code:



user.avatar = nil
user.save


and also tried these methods after checking
question 1 and question2 about same issue



user.avatar.destroy
user.save

#also tried this
user.update(avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil)


I am using rails 5.1.6, paperclip (~> 5.2.0)










share|improve this question


























    3















    My user model has avatar attachment



    class User
    has_attached_file :avatar, styles: medium: '300x300#', thumb: '150x150#' , default_url: :default_url_by_gender

    def default_url_by_gender
    if female?
    'female.svg'
    else
    'male.svg'
    end
    end
    end


    Before uploading an image the avatar.url return default url, when I upload an image and save then delete it, the avatar.url still direct to the deleted image url not the default_url



    I delete the avatar with following code:



    user.avatar = nil
    user.save


    and also tried these methods after checking
    question 1 and question2 about same issue



    user.avatar.destroy
    user.save

    #also tried this
    user.update(avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil)


    I am using rails 5.1.6, paperclip (~> 5.2.0)










    share|improve this question
























      3












      3








      3








      My user model has avatar attachment



      class User
      has_attached_file :avatar, styles: medium: '300x300#', thumb: '150x150#' , default_url: :default_url_by_gender

      def default_url_by_gender
      if female?
      'female.svg'
      else
      'male.svg'
      end
      end
      end


      Before uploading an image the avatar.url return default url, when I upload an image and save then delete it, the avatar.url still direct to the deleted image url not the default_url



      I delete the avatar with following code:



      user.avatar = nil
      user.save


      and also tried these methods after checking
      question 1 and question2 about same issue



      user.avatar.destroy
      user.save

      #also tried this
      user.update(avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil)


      I am using rails 5.1.6, paperclip (~> 5.2.0)










      share|improve this question














      My user model has avatar attachment



      class User
      has_attached_file :avatar, styles: medium: '300x300#', thumb: '150x150#' , default_url: :default_url_by_gender

      def default_url_by_gender
      if female?
      'female.svg'
      else
      'male.svg'
      end
      end
      end


      Before uploading an image the avatar.url return default url, when I upload an image and save then delete it, the avatar.url still direct to the deleted image url not the default_url



      I delete the avatar with following code:



      user.avatar = nil
      user.save


      and also tried these methods after checking
      question 1 and question2 about same issue



      user.avatar.destroy
      user.save

      #also tried this
      user.update(avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil)


      I am using rails 5.1.6, paperclip (~> 5.2.0)







      ruby-on-rails ruby paperclip






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 15:39









      Selim AlawwaSelim Alawwa

      7917




      7917






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You need to use purge, not destroy. From the official docs, https://edgeguides.rubyonrails.org/active_storage_overview.html#removing-files




          To remove an attachment from a model, call purge on the attachment. Removal can be done in the background if your application is setup to use Active Job. Purging deletes the blob and the file from the storage service.




          # Synchronously destroy the avatar and actual resource files.
          user.avatar.purge

          # Destroy the associated models and actual resource files async, via Active Job.
          user.avatar.purge_later


          Deleting the asset in the way you've done does not remove the attachment between the instance and the asset:



          user.avatar.destroy
          user.avatar.attached? => true

          user.avatar.purge
          user.avatar.attached? => false





          share|improve this answer























          • The avatar is a PaperClip attachment, when I run user.avatar.purge, I get NoMethodError: undefined method purge' for #<Paperclip::Attachment:`

            – Selim Alawwa
            Mar 10 at 7:49












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047607%2frails-paperclip-deleting-attachment-with-default-url-option-doesnt-change-atta%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You need to use purge, not destroy. From the official docs, https://edgeguides.rubyonrails.org/active_storage_overview.html#removing-files




          To remove an attachment from a model, call purge on the attachment. Removal can be done in the background if your application is setup to use Active Job. Purging deletes the blob and the file from the storage service.




          # Synchronously destroy the avatar and actual resource files.
          user.avatar.purge

          # Destroy the associated models and actual resource files async, via Active Job.
          user.avatar.purge_later


          Deleting the asset in the way you've done does not remove the attachment between the instance and the asset:



          user.avatar.destroy
          user.avatar.attached? => true

          user.avatar.purge
          user.avatar.attached? => false





          share|improve this answer























          • The avatar is a PaperClip attachment, when I run user.avatar.purge, I get NoMethodError: undefined method purge' for #<Paperclip::Attachment:`

            – Selim Alawwa
            Mar 10 at 7:49
















          1














          You need to use purge, not destroy. From the official docs, https://edgeguides.rubyonrails.org/active_storage_overview.html#removing-files




          To remove an attachment from a model, call purge on the attachment. Removal can be done in the background if your application is setup to use Active Job. Purging deletes the blob and the file from the storage service.




          # Synchronously destroy the avatar and actual resource files.
          user.avatar.purge

          # Destroy the associated models and actual resource files async, via Active Job.
          user.avatar.purge_later


          Deleting the asset in the way you've done does not remove the attachment between the instance and the asset:



          user.avatar.destroy
          user.avatar.attached? => true

          user.avatar.purge
          user.avatar.attached? => false





          share|improve this answer























          • The avatar is a PaperClip attachment, when I run user.avatar.purge, I get NoMethodError: undefined method purge' for #<Paperclip::Attachment:`

            – Selim Alawwa
            Mar 10 at 7:49














          1












          1








          1







          You need to use purge, not destroy. From the official docs, https://edgeguides.rubyonrails.org/active_storage_overview.html#removing-files




          To remove an attachment from a model, call purge on the attachment. Removal can be done in the background if your application is setup to use Active Job. Purging deletes the blob and the file from the storage service.




          # Synchronously destroy the avatar and actual resource files.
          user.avatar.purge

          # Destroy the associated models and actual resource files async, via Active Job.
          user.avatar.purge_later


          Deleting the asset in the way you've done does not remove the attachment between the instance and the asset:



          user.avatar.destroy
          user.avatar.attached? => true

          user.avatar.purge
          user.avatar.attached? => false





          share|improve this answer













          You need to use purge, not destroy. From the official docs, https://edgeguides.rubyonrails.org/active_storage_overview.html#removing-files




          To remove an attachment from a model, call purge on the attachment. Removal can be done in the background if your application is setup to use Active Job. Purging deletes the blob and the file from the storage service.




          # Synchronously destroy the avatar and actual resource files.
          user.avatar.purge

          # Destroy the associated models and actual resource files async, via Active Job.
          user.avatar.purge_later


          Deleting the asset in the way you've done does not remove the attachment between the instance and the asset:



          user.avatar.destroy
          user.avatar.attached? => true

          user.avatar.purge
          user.avatar.attached? => false






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 16:03









          MarkMark

          2,1311725




          2,1311725












          • The avatar is a PaperClip attachment, when I run user.avatar.purge, I get NoMethodError: undefined method purge' for #<Paperclip::Attachment:`

            – Selim Alawwa
            Mar 10 at 7:49


















          • The avatar is a PaperClip attachment, when I run user.avatar.purge, I get NoMethodError: undefined method purge' for #<Paperclip::Attachment:`

            – Selim Alawwa
            Mar 10 at 7:49

















          The avatar is a PaperClip attachment, when I run user.avatar.purge, I get NoMethodError: undefined method purge' for #<Paperclip::Attachment:`

          – Selim Alawwa
          Mar 10 at 7:49






          The avatar is a PaperClip attachment, when I run user.avatar.purge, I get NoMethodError: undefined method purge' for #<Paperclip::Attachment:`

          – Selim Alawwa
          Mar 10 at 7:49




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047607%2frails-paperclip-deleting-attachment-with-default-url-option-doesnt-change-atta%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved