ruby 未定义的方法'html_fallback_for_js'在MySQL View::Base中

jum4pzuy  于 2023-10-17  发布在  Ruby
关注(0)|答案(2)|浏览(76)

我最近升级了一个项目到ruby 3.2.2rails 6.1我遇到了ActionView::Base的问题。在最近的升级中,我需要向ActionView::Base.new传递3个参数,而不是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

uubf1zoe

uubf1zoe1#

在Rails 6.1中,ActionView::Base.new有3个参数:lookup_context,分配,控制器
但是你传递了ActionView::PathSet示例而不是ActionView::LookupContext
这个对象没有这样的getter,这就是为什么你有错误
而不是将此 Package 路径设置到查找上下文中。另外,在新的Ruby中,如果名称等于键值,则不需要重复的值

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

之后,您可以使用此视图进行渲染

00jrzges

00jrzges2#

this answer
我已将呼叫从ActionView::Base.new更改为ActionView::Base.with_empty_template_cache.new
也是从上下文到LookupContext的参数之一,如下所示:从ActionController::Base.view_pathsActionView::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
    )

相关问题