Question

Getting this error:

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 middleware:

use PDFKit::Middleware

rake routes:

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

If I put .pdf at the end of the URL, I get this:

Routing Error

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

Anyone know wth I'm doing wrong? Thanks in advance.

Was it helpful?

Solution

Use render_to_string instead of render

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top