I'm using rails 3.0 and PDFKit. SASS and HAML but I don't have the asset pipeline implemented yet.
If I make a call from a controller I can generate perfect styled pdf with images, calling PDFKit.new passing render_to_string :show. But if I do the same through a rake task, my PDF is generated without styles, and image_tag helper throws an error like this:
can't convert nil into String
Surely, I'm doing something wrong in the rake task... but everything works in the controller... What I'm missing? Should I include something in the rake task? or maybe use another view with inline styles and absolute paths? the calls are these:
CONTROLLER VERSION
def generate_html_invoice
render_to_string :show, layout: 'mypdflayout'
end
mypdf = PDFKit.new html_generator
RAKE TASK VERSION
def generate_html_invoice
invoice_view = ActionView::Base.new(MyWeb::Application.config.paths["app/views"].first)
invoice_view.assign({ ....... various params here})
html_invoice = invoice_view.render(template: "invoices/show", layout: 'mypdflayout')
return html_invoice
mypdf = PDFKit.new html_generator
The same error is thrown by image_tag
helper and stylesheet_link_tag
helper
An alternative way could be instantiate the controller in the rake task but.. is it possible? and, is it a good practice?