Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ahh I finally did it !</p> <p>Thanks for your answer Sean but I was not looking for a better Gem, I was looking for a solution to my issue.</p> <p>For some reason I couldn't use the render_to_string method in my Model... So I created my export_to_pdf method on my model:</p> <pre><code> def export_to_pdf bill = self project = self.project path = "facture_#{self.project.id}_#{self.bill_number}_#{Date.today.strftime('%Y_%m_%d')}.pdf" Plus::BillingItemsController.new._to_pdf(bill.id) if File.exists?(path) return path else return nil end end </code></pre> <p>As you can see I call my Controller in my Model. Here is my _to_pdf method:</p> <pre><code> def _to_pdf(bill_id) @bill = Plus::ProjectBill.find_by_id(bill_id) @project = @bill.project path = "#{RAILS_ROOT}/public/xls/facture_#{@project.id}_#{@bill.bill_number}_#{Date.today.strftime('%Y_%m_%d')}.pdf" av = ActionView::Base.new(Rails::Configuration.new.view_path) av.class_eval do include ApplicationHelper include ActionController::UrlWriter default_url_options[:host] = 'mysite.com' end av.extend ApplicationController.master_helper_module html = av.render(:partial =&gt; "/plus/billing_items/bill_for_pdf.haml", :locals =&gt; {:bill =&gt; @bill}) data = to_pdf(html, false, {:header =&gt; '', :headfootsize =&gt; 0, :outfile =&gt; path}) end </code></pre> <p>My to_pdf function is just doing the PDF::HTMLDoc.new and the set_option of links, logoimage , etc. and return pdf.generate</p> <p>I hope this can help someone someday somewhere !</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload