Problemas al instanciar un objeto de una clase que hereda de Prawn::Document.

8 views
Skip to first unread message

Diego Bertaso

unread,
Sep 29, 2019, 2:32:45 AM9/29/19
to RubyVE - Grupo de Usuarios Ruby de Venezuela
Hola a todos.

Cuando trato de instanciar un objeto a partir de una clase que hereda de Prawn::Document, se prenta el error TypeError: "pdf" is not a class/module. Esto lo hice siguiendo la documentación existente para esto.

A continuación anexo el código para ver si me pueden indicar donde estoy cometiendo el error y me puedan ayudar a resolverlo.

Estoy trabajando con Rails 4.2.10, Ruby 2.4.6 y Prawn 2.2.2.

Código en archivo 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)

Código en el 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

Código de la clase pdf (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

Después de ejecutar la instrucción pdf = PrecioGacetaPdf.new, me arroja el error siguiente:

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>'


Gracias por adelantado por la ayuda que me puedan prestar.

Diego Bertaso
Reply all
Reply to author
Forward
0 new messages