Hi Everybody.
Greetings.
I am presented with the error "" pdf "is not a class / module" when I try to create an instance of the PriceGacetaPdf class which inherits from Prawn :: Document.
Below I attach the code to see if any of you can tell me what I am doing wrong.
I am using Ruby 2.4.6, Rails 4.2.10 and Prawn 2.2.2.
mime_types.rb
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register "application/pdf", :pdf unless Mime::Type.lookup_by_extension(:pdf)
Code in Controller
def show
@precio_gaceta = PrecioGaceta.find(params[:id])
respond_to do |format|
format.html
format.pdf do
pdf = PrecioGacetaPdf.new
send_data pdf.render, filename: "Precio#{@precio_gaceta.id.to_s}.pdf",
type: "application/pdf",
disposition: "inline"
end
end
end
Code in file precio_gaceta_pdf,rb
class PrecioGacetaPdf < Prawn::Document
def initialize
puts "Entro en Initialize"
super(:page_size=>"LETTER")
puts "paso por super"
text "Precio Gaceta va aquí"
end
def new
end
end
Result after execute the sentence pdf = PrecioGacetaPdf.new
TypeError: "pdf" is not a class/module
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/pdf-core-0.7.0/lib/pdf/core/document_state.rb:14:in `initialize'
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/prawn-2.2.2/lib/prawn/document.rb:211:in `new'
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/prawn-2.2.2/lib/prawn/document.rb:211:in `initialize'
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/prawn-2.2.2/lib/prawn/document.rb:142:in `new'
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/prawn-2.2.2/lib/prawn/document.rb:142:in `generate'
from (irb):2
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in `start'
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/railties-4.2.10/lib/rails/commands/console.rb:9:in `start'
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/dbertaso/.rvm/gems/ruby-2.4.6@rails42-ruby246/gems/railties-4.2.10/lib/rails/commands.rb:17:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Thanks in advance for your help.