**87.Generating RSS Feeds (revised) **
153.PDFs with Prawn
402.Better Errors & RailsPanel
**87.Generating RSS Feeds (revised) **
153.PDFs with Prawn
錯誤:
Your document includes text that's not compatible with the Windows-1252 character set. If you need full UTF-8 support, use TTF fonts instead of PDF's built-in fonts .
尋找字體解決:在mac的font book中找到宋體辜王,拷貝裹纳。代碼顯示如下:
#clients_controller.rb
def download_pdf
client = Client.find(params[:id])
send_data generate_pdf(client), filename: "#{client.name}.pdf", type: "application/pdf"
end
private
def generate_pdf(client)
Prawn::Document.new do
#建立字體
font_families["msyh"] = {
:normal => { :file => "/Users/jayzen/Desktop/Fangsong.ttf" }
}
#使用已經(jīng)創(chuàng)建好的字體進(jìn)行顯示
font("msyh") do
text client.name, align: :center
text "Address: #{client.address}"
text "Email: #{client.email}"
end
end.render
end
402.Better Errors & RailsPanel
本章節(jié)是介紹在開發(fā)模式下面的幾個gem,用于調(diào)試錯誤和觀察運行時狀況,其中內(nèi)容在gorails里面也有提到库北,這個章節(jié)主要是增加一個gem,和一個chrome插件敷矫,完整的gem列表如下:
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end
另外chrome的插件名稱為RailsPanel肉微。