Reputation: 21
Currently I am rendering a view in Rails 4 outside of a Controller with this code:
av = ActionView::Base.new(ActionController::Base.view_paths, {}, ActionController::Base.new)
av.config = Rails.application.config.action_controller
av.class_eval do
include ApplicationHelper
end
html = av.render(
file: '/users/index',
locals: {}
)
How can I render the view inside of a layout? The following does not work:
html = av.render(
file: '/users/index',
locals: {}
layout: 'layouts/application'
)
Thanks!
Upvotes: 1
Views: 798
Reputation: 21
I solved it. It works fine as expected:
html = av.render(
file: '/users/index',
locals: {}
layout: 'layouts/application'
)
What does not work is:
html = av.render(
file: '/users/index.pdf',
locals: {}
layout: 'layouts/application'
)
looks like it searches for a layout layouts/application.pdf.erb
or similar. It does fail silently though.
Upvotes: 1