Search code examples
ruby-on-railsrubyrails-activestorageruby-on-rails-5.2

ActiveStorage - retrieving file URL


I am migrating from deprecated paperclip gem to ActiveStorage and wondering how can I get hold of attachment URL in the model (for example if I want to add it to custom as_json method, some elasticshearh data etc.)

Couldn't find anything in documentation for that particular use case.


Solution

  • file = fetch_your_file
    
    link = rails_blob_path(file, disposition: 'attachment') 
    

    will return the attachment link