hi i am a bit stuck with this. what i am going to work out is that i have a file called ticket_pdf.rb in lib/ directory which i am planning to generate some invoice PDFs for my app. I want to call a function of this class to generate the PDFs from my controller actions.
the ticket_pdf.rb looks like this
class TicketPDF
def generate_pdf (purchase)
puts "Ticket ID = #{purchase.ID}"
end
end
in a controller I action i do this.
class Customer::MyController < ApplicationController
require 'ticket_pdf'
def show
ticket = TicketPDF.new
end
end
when i try to create an object like this it give me a 500 error like this one.
uninitialized constant Customer::MyController::TicketPDF
what i am doing wrong here ?
Try
ticket = ::TicketPDF.new
You have created TicketPDF in the top level namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With