dfaulken
dfaulken

Reputation: 516

Undefined method `pdf` with prawn-rails

Trying to set up a basic PDF template with prawn-rails, and something's not quite right.

Gemfile:

gem 'prawn-rails'

which does grab the latest version (1.0.0).

Controller:

def show
  respond_to do |format|
    format.pdf { render pdf: 'show.pdf.prawn' }
    # ...
  end
end

HAML view:

= link_to object_url(object, format: :pdf) do
  %button.btn.btn.default Print

show.pdf.prawn:

prawn_document do
  pdf.text "Some text"
end

config/initializers/prawn-rails.rb:

require 'prawn-rails'

PrawnRails.config do |config|
  config.page_layout = :portrait
  config.page_size = 'LETTER'
  config.skip_page_creation = true
end

This is all according to the README of the prawn-rails repository.

But I get ActionView::Template::Error (undefined local variable or method 'pdf' for #<#<Class:0x005618ff5021e8>:0x005618ff97b968>).

Any thoughts? Should I just report this as an issue on the repo?

Upvotes: 0

Views: 590

Answers (1)

GoGoCarl
GoGoCarl

Reputation: 2519

Should be:

prawn_document do |pdf|
  pdf.text "Some text"
end

I'd send them a note and tell them to update their README.

Upvotes: 1

Related Questions