Last active
October 20, 2015 18:47
-
-
Save ilake/3b201192ee2ba8c008f4 to your computer and use it in GitHub Desktop.
render view not in controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://makandracards.com/makandra/17751-render-a-view-from-a-model-in-rails | |
# https://github.com/yappbox/render_anywhere | |
# http://stackoverflow.com/questions/18263220/rendering-partials-view-in-a-rake-task-background-job-model-in-rails-4 | |
# http://ruby-china.org/topics/12193 | |
# http://alphahydrae.com/2013/06/rails-3-rendering-views-outside-a-controller/ | |
def render_to_string(options = {}) | |
av = ActionView::Base.new(ActionController::Base.view_paths) | |
av.extend TranslationHelper | |
av.render(:template => "contacts/index.pdf.erb", | |
:locals => {:setting => school.setting, | |
:@school => school | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment