Have you required Ruby's native CSV library in an initializer yet? Add a comment. Active Oldest Votes. Improve this answer. That did the trick. Glad to hear it worked. Try this format. I tried that but it's not downloading or even displaying the file in the browser. Nothing happens when I click on the link.
I added the content of my index. I found other solution that worked for me Rails 3. It could be downloaded from controller: Inside the block format. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. The show action has 2 formats html and pdf , which will be used to define how the content is rendered. For example, if you access the invoice directly without the. Try it here:. You can configure the options however you need see wkhtmltopdf documentation for additional details.
To customize the layout of the PDF, use the following settings:. For this example, I will only use the stylesheet helper:. Now you need to make sure all the assets will are precompiled according to the official GitHub, this next step is essential for your gem to work perfectly when you deploy to production :.
The above array will need to include every stylesheet and JavaScript library that you're using. You can now deploy your application for generating PDFs. Here's our demo application that we deployed to a free Heroku web dyno. Using wkhtmltopdf is a quick and easy way to generate PDFs from Ruby. However, if you need to generate PDFs from something other than HTML, want to integrate this into a workflow, or need precise control over positioning, then you're out of luck with wkhtmltopdf.
These engines are best suited for simple documents where you can afford to have some inconsistencies or failures. You can get started with a free trial and then check out some of the Ruby code samples to help get you up and running quickly. You can find the source code for this blog post at our GitHub rails-generate-pdf. Should work when the file is placed correctly. Let me know if you can't move your file to public folder.
Improve this answer. I'm pretty sure all resources should be placed in the assets folder since rails 3 but since it worked it will do for now.
Sorry it was not specified which version of rails you were using — felipeclopes. Check the new edit I just made for Rails 3. Hope it helps you! No need for this approach if those pdf's are available to everyone. With Rails 3. Navi I tried your approach but I keep getting the No route matches error. Can you see the issue here? How would you adjust this for multiple files? IE a folder of files one was generating links to in a list — Btuman. Show 1 more comment.
If the files are static meaning they don't change , place them in the public folder. Cruz Nunez Cruz Nunez 2, 1 1 gold badge 20 20 silver badges 32 32 bronze badges. I think this attitude is not right for newbie SO users like me. Sign up or log in Sign up using Google.
0コメント