Rails active storage - Open/download link

rail_engine picture rail_engine · Jun 28, 2018 · Viewed 11.2k times · Source

A question on Active Storage: I just updated to rails 5.2 and I am trying to open the attached document which is saved as a blob. Currently, it's redirecting to root_path, any idea how can I open/download it instead?

My code in Rails view is:

<%= link_to(document.filename, rails_blob_path(document, disposition: "attachment")) %>

Answer

Horacio picture Horacio · Jul 27, 2018

To Download:

<%= link_to document.filename, rails_blob_path(document, disposition: 'attachment') %>

To Preview:

<%= link_to document.filename, rails_blob_path(document, disposition: 'preview') %>

Source - ActiveStorage#Linking to Files documentation