Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6588833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:05:51+00:00 2026-05-25T17:05:51+00:00

I have looked around on the internet, but do not seem able to find

  • 0

I have looked around on the internet, but do not seem able to find how to display a PDF in rails (I can only find info on how to create one).

Does anyone know what code/gem I need to display one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:05:51+00:00Added an answer on May 25, 2026 at 5:05 pm

    In your controller:

    def pdf
      pdf_filename = File.join(Rails.root, "tmp/my_document.pdf")
      send_file(pdf_filename, :filename => "your_document.pdf", :type => "application/pdf")
    end
    

    In config/environment/production.rb:

    config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
    

    or

    config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
    

    The config modification is required because it enables the web server to send the file directly from the disk, which gives a nice performance boost.

    Update

    If you want to display it instead of downloading it, use the :disposition option of send_file:

    send_file(pdf_filename, :filename => "your_document.pdf", :disposition => 'inline', :type => "application/pdf")
    

    If you want to display it inline, this question will be much more complete that I could ever be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked around the internet but haven't been able to find a working
I have looked around stackoverflow and search the internet but did not find a
i've looked around the internet but can't seem to find what i need. I
I have looked around here and the Internet in general but it seems this
Sorry if this is obvious but have looked around and can't get this working:
I've looked around and have bits and pieces but can't put the puzzle together.
I've looked around but have yet to find a great solution the the following
I have looked around and could not find any similar question. Here is the
I have looked around, but have been unable to find anything that helps me.
I have a rails 3 application and looked around in the internet for daemons

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.