Skip to content

Instantly share code, notes, and snippets.

@swaathi
Last active July 22, 2016 08:06
Show Gist options
  • Save swaathi/b931d3992443cbdf2f22 to your computer and use it in GitHub Desktop.
Save swaathi/b931d3992443cbdf2f22 to your computer and use it in GitHub Desktop.
Preview files outside Public or Assets folder in Rails
# In your controller use the Rails in-built function, send_file to send the file to your browser for preview.
# Specify the filepath of your file in the send_file function.
def preview
send_file "#{Rails.root}/uploads/pictures/#{@file.name}"
end
# Create a route for your preview function.
resources :files do
member do
get 'preview'
end
end
<!-- In your view page, use the various tags provided by Rails to display your file.-->
<%= image_tag preview_myfile_path(@file) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment