ActionView::Base 中未定义的方法`html_fallback_for_js'

问题描述 投票:0回答:2

我最近将一个项目升级为

ruby 3.2.2
rails 6.1
我遇到了
ActionView::Base
的问题。通过最近的升级,我需要将 3 个参数传递给
ActionView::Base.new
,而不是 2 个。从文档来看,
ActionView
现在接收
lookup_context, assigns, controller

view = ActionView::Base.new(
  ActionController::Base.view_paths, 
 {
  client: client,  
  report: self.report, 
},
nil
)

所以我通过传递

nil
来修复它(如上所示),但现在我得到了一个不同的错误:

/usr/local/rvm/gems/ruby-3.2.2/gems/actionview-6.1.7.3/lib/action_view/base.rb:264:in `in_rendering_context': undefined method `html_fallback_for_js' for #<ActionView::PathSet:0x0000000110898f58 @paths=[#<ActionView::OptimizedFileSystemResolver:0x000000010fa92670 @pattern=":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", @unbound_templates=#<Concurrent::Map:0x0000000110898f30 entries=0 default_proc=nil>, @path_parser=#<ActionView::Resolver::PathParser:0x0000000110898eb8>, @cache=#<ActionView::Resolver::Cache:0x0000000110898e90 keys=0 queries=0>, @path="/Users/Mari/reporting/app/views">, #<ActionView::OptimizedFileSystemResolver:0x000000010fa92760 @pattern=":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", @unbound_templates=#<Concurrent::Map:0x00000001108994a8 entries=0 default_proc=nil>, @path_parser=#<ActionView::Resolver::PathParser:0x0000000110899408>, @cache=#<ActionView::Resolver::Cache:0x00000001108993e0 keys=0 queries=0>, @path="/usr/local/rvm/gems/ruby-3.2.2/gems/graphiql-rails-1.9.0/app/views">, #<ActionView::OptimizedFileSystemResolver:0x000000010fa92850 @pattern=":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", @unbound_templates=#<Concurrent::Map:0x0000000110899ac0 entries=0 default_proc=nil>, @path_parser=#<ActionView::Resolver::PathParser:0x0000000110899a48>, @cache=#<ActionView::Resolver::Cache:0x0000000110899a20 keys=0 queries=0>, @path="/usr/local/rvm/gems/ruby-3.2.2/gems/teaspoon-1.2.2/app/views">, #<ActionView::OptimizedFileSystemResolver:0x000000010fa92940 @pattern=":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", @unbound_templates=#<Concurrent::Map:0x0000000110899e80 entries=0 default_proc=nil>, @path_parser=#<ActionView::Resolver::PathParser:0x0000000110899e08>, @cache=#<ActionView::Resolver::Cache:0x0000000110899de0 keys=0 queries=0>, @path="/usr/local/rvm/gems/ruby-3.2.2/gems/devise-security-0.18.0/app/views">, #<ActionView::OptimizedFileSystemResolver:0x000000010fa92990 @pattern=":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", @unbound_templates=#<Concurrent::Map:0x000000011089a268 entries=0 default_proc=nil>, @path_parser=#<ActionView::Resolver::PathParser:0x000000011089a1f0>, @cache=#<ActionView::Resolver::Cache:0x000000011089a1c8 keys=0 queries=0>, @path="/usr/local/rvm/gems/ruby-3.2.2/gems/devise-4.8.0/app/views">, #<ActionView::OptimizedFileSystemResolver:0x000000010fa929e0 @pattern=":prefix/:action{.:locale,}{.:formats,}{+:variants,}{.:handlers,}", @unbound_templates=#<Concurrent::Map:0x000000011089a740 entries=0 default_proc=nil>, @path_parser=#<ActionView::Resolver::PathParser:0x000000011089a6c8>, @cache=#<ActionView::Resolver::Cache:0x000000011089a650 keys=0 queries=0>, @path="/usr/local/rvm/gems/ruby-3.2.2/gems/ckeditor-4.3.0/app/views">]> (NoMethodError)

      if !lookup_context.html_fallback_for_js && options[:formats]

actionview
版本是
6.1.7.3

ruby-on-rails ruby actionview ruby-on-rails-6.1
2个回答
0
投票

在 Rails 6.1 中

ActionView::Base.new
需要 3 个参数:lookup_context、分配、控制器

但是您传递了

ActionView::PathSet
实例而不是
ActionView::LookupContext

这个对象没有这样的getter,这就是你有错误的原因

而不是将此包装路径设置到查找上下文中。另外,在新的 Ruby 中,如果名称与键名称相同,则不需要重复值

view =
  ActionView::Base.new(
    ActionView::LookupContext.new(ActionController::Base.view_paths),
    { client:, report: },
    nil,
  )

之后就可以使用这个视图进行渲染了


0
投票

来自这个答案

我已将通话从

ActionView::Base.new
更改为
ActionView::Base.with_empty_template_cache.new

也是从上下文到

LookupContext
的参数之一,如下所示: 从
ActionController::Base.view_paths
ActionView::LookupContext.new(ActionController::Base.view_paths)

现在的通话如下所示:

   view = ActionView::Base.with_empty_template_cache.new(
      ActionView::LookupContext.new(ActionController::Base.view_paths), 
     {
      client: client, 
      report: self.report, 
    }, nil
    )
© www.soinside.com 2019 - 2024. All rights reserved.