Last active
July 22, 2016 08:06
-
-
Save swaathi/b931d3992443cbdf2f22 to your computer and use it in GitHub Desktop.
Preview files outside Public or Assets folder in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a route for your preview function. | |
resources :files do | |
member do | |
get 'preview' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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