I\'m trying to create an HTML string using a view. I would like to render this from a class that is not a controller. How can I use the rails rendering engine outside a co
You can use ActionView::Base to achieve this.
view = ActionView::Base.new(ActionController::Base.view_paths, {})
view.render(file: 'template.html.erb')
The ActionView::Base initialize takes:
assigns
hash, providing the variables for the templateIf you would like to include helpers, you can use class_eval to include them:
view.class_eval do
include ApplicationHelper
# any other custom helpers can be included here
end