我在将Rails 6升级到7后,我的Rails应用程序出现了问题。当我尝试render_to_string
一个模板时,我会收到ActionView :: MissingTemplate异常。
由于这之前一直正常工作,所以我不禁想到Rails 7有一些新的方法,但我无法找到。
下面是我的代码:
控制器
class SomethingController < ApplicationController
...
def my_action
html_string = render_to_string(template: 'something/template.html.erb', locals: {id: params[:id]})
end
end
我的期望(以及我过去的行为)是获取经过处理的模板视图,但我得到的是异常:
ActionView::MissingTemplate (Missing template something/template.html.erb with {:locale=>[:"pt-BR", :pt], :formats=>[:pdf], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}.
Searched in:
* "/Users/user/rails/rn_igreja/app/views"
* "/Users/user/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/devise-i18n-1.10.2/app/views"
* "/Users/user/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/devise-4.8.1/app/views"
* "/Users/user/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/actiontext-7.0.1/app/views"
* "/Users/user/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/actionmailbox-7.0.1/app/views"
):
app/controllers/something_controller.rb:16:in `block in my_action'
app/controllers/something_controller.rb:12:in `my_action'
附加细节:
- Ruby 版本:3.1.0
- Rails 版本:7.0.2
请告诉我我错过了什么,非常感谢。