Skip to content

Instantly share code, notes, and snippets.

@sideshowcoder
Last active December 14, 2015 01:49
Show Gist options
  • Save sideshowcoder/5009089 to your computer and use it in GitHub Desktop.
Save sideshowcoder/5009089 to your computer and use it in GitHub Desktop.
Render from model in rails
class SomeModel < ActiveRecord::Base
...
def render_pdf
ac = ApplicationController.new
ac.instance_variable_set("@some_variable_needed_in_template", some_variable)
pdf = ac.render_to_string(pdf: "the_pdf_filename", template: 'pdf_templates/filename')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment