目前,我正在使用以下代码在Controller外部的Rails 4中呈现视图:
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: {}
)
如何在布局中渲染视图? 以下不起作用:
html = av.render(
file: '/users/index',
locals: {}
layout: 'layouts/application'
)
谢谢!
答案 0 :(得分:1)
我解决了。它按预期工作正常:
html = av.render(
file: '/users/index',
locals: {}
layout: 'layouts/application'
)
什么行不通:
html = av.render(
file: '/users/index.pdf',
locals: {}
layout: 'layouts/application'
)
看起来像是在搜索布局layouts/application.pdf.erb
或类似内容。它确实无声地失败。