I just want to display a pdf that is stored locally - somewhere in my Rails app folders. I don’t want to use complex cloud services, generate a pdf or use fancy routing. I just want to use a tag to point to the file.
2 Likes
<a href=<%= pdf_path_url %>>Who is an...?</a>
class PagesController < ApplicationController
def home
end
def Pdf
fname = File.join(Rails.root, 'who_is_an_addict.pdf')
send_file(fname, :filename=>'who_is_an_addict.pdf', :disposition=>'inline')
end
end
ROUTES
<a href=<%= pdf_path_url %>>Who is an... ?</a>
Rails.application.routes.draw do
root 'pages#home'
get 'fems-and-thems' => 'pages#fems-and-thems'
get 'asc' => 'pages#asc'
get 'whois' => 'pages#who_is_an...'
get 'pdf_path' => 'pages#Pdf'
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/")
# root "articles#index"
end
2 Likes
Okay, does this work for you? Or are you having an issue with this approach? One thing I see missing here is any notion of the format. By default, a get is going to prefer text/html, not application/pdf.
Walter
I try this work for me thanks…
Put it in the public
folder in your project. Let’s say the file is named project.pdf
. Then just use a normal anchor
<a href="/project.pdf">Click to download</a>
2 Likes