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 6962695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:41:38+00:00 2026-05-27T15:41:38+00:00

I have a problem when trying to see a .pdf file (generated with PDFKit)

  • 0

I have a problem when trying to see a .pdf file (generated with PDFKit) unauthenticated, just going directly from a given url host/.../profile.pdf. I, as expected, am asked to enter the credentials as shown in the image (Not in the users/sign_in path):

asking for authentication

I enter the correct credentials, the box goes up and down and asks for the credentials again. It could seem like the user or password are wrong, but they aren’t. The relevant code from the controller is here:

class Entrepreneur::ProfilesController < ApplicationController
  before_filter :authenticate_user!

  def show
    respond_to do |format|
      format.pdf do
        html = render_to_string(:layout => false , :action => "show.html.haml")
        kit = PDFKit.new(html)
        send_data(kit.to_pdf, :filename => "name.pdf", :type => 'application/pdf')
      end
    end
  end
end

Nothing fancy as you can see. I tried to remove the show action from the filter (before_filter :authenticate_user!, :except => [:show]) and write myself a custom filter to redirect unauthenticated users to new_session_path, but doing so I don’t know how to, once signed up, redirect the user to the pdf show.

In short, devise asks for my credentials when accessing a pdf show and doesn’t accept them. How can I get the user to the sign_in page and redirect back to the pdf once signed?

I’m using Rails 3.0.7, Ruby 1.8.7 and Devise 1.1.5.

Thanks!

  • 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-27T15:41:38+00:00Added an answer on May 27, 2026 at 3:41 pm

    First, make sure that it’s actually Rails serving the PDF and not a web server in front of it. (Depending on your configuration, it could be the request is never getting to Rails in the first place.)

    Assuming it is Rails serving the file, then you should check your devise.rb configuration file. You may need to make :pdf a navigational format which will allow Devise to issue a 302 redirect to your sign_in page:

    config.navigational_formats = [:html, :pdf] # you may have additional formats

    Also, you may need to add PDF to your mime_types.rb initializer if it’s not there already:

    Mime::Type.register 'application/pdf', :pdf

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

Sidebar

Related Questions

I have a problem when I'm trying to delete an image file. I always
I have a problem when trying to deploy my project in JBoss. The generated
I'm trying to get values from xml, and I have problem with empty value.
I have a problem when trying to execute this update statement (below) using C#
Hey all, i have a problem with trying to get 2 forms to close
I have a problem I'm trying to solve involving interfaceing a C++ program with
I have run into a problem trying to modify a form I myself have
Ok I have this problem I'm trying to use Jquery to load a partial
Greetings, I have problem with errorPlacement, I'm trying to place the error message next
I have this problem I've been trying to tackle for a while. I have

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.