Note that there are some explanatory texts on larger screens.

plurals
  1. POPDF export from a Model method using render_to_string
    text
    copied!<p>I need to implement a _to_pdf method on my ProjectBill model which generates a PDF of my bill at this place:</p> <pre><code>/public/xls/bills/project_#{project.number}_bill_#{bill.number}.pdf </code></pre> <p>My application is using HTMLDoc for generating PDF. I am using <strong>Rails 2.3.11</strong>. With the HTMLDoc gem, I need to pass a <strong>render_to_string</strong> of my partial view <strong>_bill.pdf.haml</strong>, wich is not accessible in the model (only in the controllers), to HTMLDoc. </p> <p>I already have an export_to_pdf action in my controller, triggered by the user when he wants an export (this one works). The model method will be called by a scheduled task, an emailer sending the bills when the scheduled_date is equal to Date.today.</p> <p>I've already tried tons of solutions:</p> <ul> <li><a href="http://www.omninerd.com/articles/render_to_string_in_Rails_Models_or_Rake_Tasks/print_friendly" rel="nofollow">http://www.omninerd.com/articles/render_to_string_in_Rails_Models_or_Rake_Tasks/print_friendly</a></li> <li>Have a to_pdf action on my ProjectBill controller and call it in from Model (but not working, saying that render_to_string is not defined even if its called in the Controller)</li> <li>Use my working export_to_pdf method with a get request sent from my Model (but I figured out that I cannot really send a request from a Model...)</li> <li>Use a Helper with the render_to_string inside it (not working: undefined method)</li> <li>and even more !</li> </ul> <p>But still not working. </p> <p>Can somebody help me with this issue? Im stuck and can't find any solution...</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