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
Related
I have a Ruby on Rails app in which I want to take an existing PDF (preformatted with fields) and rewrite the PDF with data from an ActiveRecord object. (i.e. first name, last name, date of birth, etc). I'm familiar with Prawn and WickedPDF but I'm not sure that this is supported (taking an existing/formatted PDF document and rewriting it with populated data).
I've done some searching and I can't find much on this as everything points to generating custom templates in Prawn or Wicked.
Does anyone have advice on this or perhaps guidance in the right direction?
I am new to rails and trying to understand this concept, as there are many things which we write using helpers(erb/rails tags) can also be written using simple plain html , is there any other advantage to using rails/erb helper than enabling to write more simple and readable code.
As the end result of writing the erb/rails template is always going to be a plain html , so initially by writing plain html do we reduce load on server or reduce servers efforts of converting the rails/erb templates into plain html.
Note: I am specifically asking for more of static templates e.g web forms , links , form contents,etc.
Here're some of merits.
Ability to Collaborate with models and helpers
It automatically generates post url and form labels etc. So, say you're changing the name of a model or url, if you were writing plain html for all templates, you'll have to manually replace all of occurrences on your own, whereas the "rails-way" can handle them all just with one line of modification or one command execution.
Can take advantage of template libraries.
There're lots of awesome template libraries that generate html from ruby code.
https://github.com/plataformatec/simple_form
https://github.com/justinfrench/formtastic
Gives you better abstraction
It gives you good abstraction in the way that it makes you write what you want instead of how you do. For example in my previous project, I was using bootstrap2 and decided to move to bootstrap3. If I were writing plain html, I had to see all html files, and inspect sometimes intricately structured html tags, classes, and find all bootstrap2 specific elements and change them all. But thanks to the template generation gem I was using, all I had to do was basically to upgrade the gem and add a few lines to some config files.
I need to allow users the ability to create lessons, which consist of HTML and form elements. I want them to be able to take advantage of Rails' form helpers and general Ruby code to, for example, decide where and how to display error content. I realize there are security issues with giving them access to execute Ruby code, but I'll have to deal with that later if users will share deployments.
So it seems I should store the ERB files in the database and somehow call them with <%= render content_from_database %>. Is this possible? Will I affect Rails caching in some way?
Using latest Rails with Heroku (no writing to filesystem).
You should take a look at the Liquid template language
From their tagline:
Ruby library for rendering safe templates which cannot affect the
security of the server they are rendered on.
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.
I was using backbone standalone for some time but currently I am trying to integrate it with Rails. Until now I used underscore templates and the question would be if it is possible to use Rails view helpers inside the template and if it is smart thing to do at all?
Update: Here is a simple example what I am talking about.
I have a list of messages and I have a MessageView for each message, I want to render the avatar thumbnail of the message author, link to his profile and description when the message was posted. Also I use markdown for the message content. With underscore templates I don't have access to the helpers to achieve this so I am forced to create methods on the model itself which feels really wrong...
You should take a look at the EJS Embedded JavaScript Framework, which provides rails-like standard view helpers like link_to, url_for, and other form tags.
Of course, you will have to translate your custom rails templates in js, but it's a start !
I ran into the same problem where I wanted to reuse my templates between Backbone and Rails. I ran into stache before: https://github.com/agoragames/stache
You can read more about the setup here: http://slainer68.wordpress.com/2011/09/20/partial-reuse-between-rails-js-the-easy-way/
Right out of the box, your underscore templates are pure javascript, so, in that sense, you can't really embed rails helpers into them. You can, however, make those templates ejb's (or whatever templating system you use) and have rails render them. With so little information, it's impossible to figure out what your app does, but it does feel weird to me to do that. I think, typically, your javascript templates are used for rendering html on the host side after some js functionality. Maybe a better description of what you are trying to accomplish?
Update ...
So you have some set of relationships between messages and authors in your rails models correct? You'd do a similar thing in your backbone models. So, you've got a User model, and a Message model. User has_many Messages, and Message has_one User. You can model that out in backbone as well... see my answer here:
Backbone set collection attribute (for the url)
You just need to describe the relationship on the backbone side.