RailsCast[2]

**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" }
      }
      #使用已经创建好的字体进行显示
      font("msyh") do
        text client.name, align: :center
        text "Address: #{client.address}"
        text "Email: #{client.email}"
      end
    end.render
  end

402.Better Errors & RailsPanel
本章节是介绍在开发模式下面的几个gem,用于调试错误和观察运行时状况,其中内容在gorails里面也有提到,这个章节主要是增加一个gem,和一个chrome插件,完整的gem列表如下:

group :development do 
  gem 'better_errors' 
  gem 'binding_of_caller' 
  gem 'meta_request'
end

另外chrome的插件名称为RailsPanel。

你可能感兴趣的:(RailsCast[2])