PDFKit - 未定义的方法'扫描'错误

时间:2013-05-07 22:07:16

标签: ruby-on-rails-3.2 pdfkit

出现此错误:

NoMethodError in AwardsController#certificate 
undefined method `scan' for #<Array:0x0000000354bd40>

的Gemfile:

gem 'pdfkit'

Ran bundle install

application.rb中:

require 'pdfkit'
config.middleware.use "PDFKit::Middleware"

routes.rb中:

match 'awards/certificate/:id' => 'awards#certificate', :as => :certificate, :via => :get

awards_controller:

def certificate
    @award = Award.find(params[:id])
    html = render :layout => false 
    kit = PDFKit.new(html, :page_size => 'Letter')
    kit.stylesheets << RAILS_ROOT + '/public/stylesheets/scaffold.css'
    send_data(kit.to_pdf, :filename => "#{@award.nominee_fullname Certificate}", :type => 'application/pdf')
  end

rake中间件:

use PDFKit::Middleware

rake routes:

certificate GET    /awards/certificate/:id(.:format)     awards#certificate

如果我把.pdf放在URL的末尾,我就明白了:

Routing Error

No route matches [GET] "/highfive/awards/certificate/51"

任何人都知道我做错了吗?提前谢谢。

1 个答案:

答案 0 :(得分:3)

使用render_to_string代替render