calling classes in /lib from controller actions
ruby, ruby-on-rails, ruby-on-rails-3
Solution
Try
ticket = ::TicketPDF.new
You have created TicketPDF in the top level namespace.
Problem
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 ?