Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails active storage - Open/download link

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")) %>

like image 985
Manav Avatar asked Jun 28 '18 00:06

Manav


Video Answer


1 Answers

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

like image 66
Horacio Avatar answered Oct 06 '22 19:10

Horacio