首页 > 解决方案 > Rails 6 ActionController::Base.new.render_to_string

问题描述

将我的 Rails 应用程序从 5.2 更新到 6 后,render_to_string 停止工作。

代码

ActionController::Base.new.render_to_string(file: Rails.root.join('test.html.erb'), locals: { foo: 'bar' })

test.html.erb

<%= foo %>

预期的

bar

当前的

<%= foo %>

它以前工作过,在更新到 Rails 6 之后,它只是输出文件内容而不对其进行评估。

PS.:我也尝试使用 ApplicationController API (ApplicationController.render),同样的行为。

我错过了什么吗?

标签: ruby-on-rails

解决方案


推荐阅读