我試圖查看.pdf文件(使用PDFKit生成)未經身份驗證,直接從給定網址host/.../profile.pdf
直接進入時出現問題。我,果然,要求我輸入憑據,如下圖所示(而不是在用戶/ sign_in路徑):直接訪問未經身份驗證的pdf文件時設計身份驗證
我輸入正確的憑據,箱體上下波動,並要求再次證明。它可能看起來像用戶或密碼是錯誤的,但它們不是。來自控制器的相關代碼如下:
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
沒什麼特別的,你可以看到。我試圖從篩選器中刪除顯示操作(before_filter :authenticate_user!, :except => [:show]
)併爲自己寫一個自定義篩選器以將未經身份驗證的用戶重定向到new_session_path,但這樣做我不知道如何在註冊後將用戶重定向到pdf顯示。
簡而言之,在訪問pdf文件時,設計會要求我的憑據,並且不接受它們。如何讓用戶訪問sign_in頁面並在簽名後重定向回pdf?
我使用Rails 3.0.7,Ruby 1.8.7和Devise 1.1.5。
謝謝!
爲什麼一個框彈出? 'before_filter:authenticate_user!'應該將你重定向到登錄頁面,不是嗎?你有什麼改變嗎? – Robin
您需要顯示驗證用戶身份的代碼。 – deviousdodo
@Robin,nope,沒有什麼變化 – scumah