Printable content in Rails - ruby-on-rails

i would like to create an application that needs to have the option to print things. I would like to ask if there is a standard way of handling such situations in Rails, or it's just a specific layout to be served when printing is asked. Is there a gem, or a good approach on doing such a thing ?

I'ved used the WickedPDF gem in the past with much success. It's based on wkhtmltopdf and what I really like about it is the PDF is generated based on a view template that's standard ERB (possibly HAML) and CSS.
It's better than going with prawn in my opinion as the template markup/styling can be reused for the PDF itself.

Related

How to get an overview over partials in ruby on rails

I am using ruby on rails 5.0.
It is common practice to use partials to share code fragments for views (e.g., in order to avoid duplication). Partials are files that start with an underscore, e.g., "_fields.html.erb".
After a certain time the directories are full of partials, and it can become quite hard to keep an overview which view calls which partials and which partial calls another partial et cetera.
Question: Is there an "easy" way or a tool or a gem that can help to give an overview of the call tree or the call dependencies? Perhaps by rendering an html page, generating a png or something similar.
Thank your for your thoughts!
This is an older gem that does that. It lets you view a tree-ish list of your partials.
https://github.com/skwp/PartialMap

Site move to Rails - partials

I'm moving my site to Rails currently.
Beforehand I used jQuery load() method to insert a separate site html element. Now moving to Rails, I have to change it. From what I've learnt so far, the best way here is to use a Rails partial for this purpose.
Is this correct?
I would recommend taking a read through the Ruby on Rails Guides which are extremely helpful if you are just getting started in Rails. The specific section that might help is their documentation on using partials.
Yes, you are correct. Partials come in handy when you want to load some HTML elements conditionally, or want to reuse them in different places. A prime example for that is the footer or header of a website. Instead of writing the code in all the required files, simply render the partial wherever required. For further reading/implementation guide, you can refer the section on partials in the RoR guide

Apply form_for data to a fillable pdf form?

I'm new to rails and gems, and I was wondering if there is a particular gem or service that I can use to take form_for data to populate the empty fields of a fillable pdf. Any suggestions all mighty SO_gods?
I would recommend using your form data to generate an html page (like you would normally in rails) and then converting that web page to a pdf. We use acts_as_flying_saucer for html->pdf conversion, it's a rails wrapper for flying_saucer which is a java app.
https://github.com/dagi3d/acts_as_flying_saucer
We make a lot of pdfs on our site, and doing them as web pages first is a very friendly and easy approach.
EDIT
I just re-read your question and saw the fillable part: you may not be able to do this with flying_saucer, sorry.
Have a look at prawn and prawn-forms: the prawn-forms extension looks like it will do what you need (i've not used prawn myself but it's quite popular).
http://prawnpdf.org/
https://github.com/cortiz/prawn-rails
https://github.com/yob/prawn-forms

Ruby on Rails Views. (Best Practice)

This might seem like a strange question. But have been pondering over this for quite some time now.
Is it better to use RAW HTML in Rails views or to go with Rails view helpers??
If i understand correctly Rails views helpers are converted back to raw HTML. So would it affect the performance of the application by a great deal ??
And is there a tool that would allow me to convert HTML to ERB :)
I'm aware of the HTML to HAML converter.
Thank you,
Certainly better to use a rails helper, as this allows you to create dynamic elements
Use Rails helpers, they guarantee the latest HTML good practice are used and up to date.

ActionMailer Multipart messages with Markdown

I'm trying to come up with an easy solution for creating multipart emails with ActionMailer to make life easier when writing HTML emails and also to make it easy to have a plain-text alternative. Basically, what I would like to have in an ideal world is a simple Markdown with Ruby file to render to a string and use as-is for the plain text mailer and run it through rdiscount or similar for the HTML part.
If you want to use José's approach he's released it as a separate gem. I just tried it with Rails 3.2.6 and it worked first time.
http://blog.plataformatec.com.br/2011/06/multipart-templates-with-markerb/
This is covered quite precisely in Crafting Rails Applications by José Valim. See section 4.2. If I might say, a great idea to use a more agnostic format than HTML for this specific purpose, especially due to the limited nature of HTML email.
My only issue with this section is that it uses a format of .merb to render markdown with embedded ruby, rather than .md.erb.

Resources