我有一个定制的FormBuilder,它有一个group方法,作 for each 标签/输入/提示/错误组合的包装器.Group方法本身非常简单,但当我try 在ERB中使用它时,就像使用"field_for"或类似方法一样,它不能正确呈现.

def group(**options, &)
  options[:class] = class_names(options[:class] || "flex flex-col mt-4", options.delete(:classes))
  
  content_tag(:div, capture(&), **options)
end

在使用表单帮助器的ViewComponent中,我可以很好地执行以下操作

def call
  @form.group(**@group) do
    concat @form.label(:tags, @label.delete(:text), **@label)
    concat @form.text_field(:tags, **@system_arguments)
  end
end

但是,如果我try 将其写入ERB的一部分,它要么根本不呈现来自组的包装器,要么只呈现Text_field而不呈现标签

<%= @form.group(**@group) do %>
  <%= @form.label(:tags, @label.delete(:text), **@label) %>
  <%= @form.text_field(:tags, **@system_arguments) %>
<% end %>

不知道我错过了什么让雇员再培训局的版本正常工作.

推荐答案

There is a fix, but it's not released yet:
https://github.com/ViewComponent/view_component/pull/1650

# Gemfile
gem "view_component", github: "ViewComponent/view_component"
# config/application.rb
config.view_component.capture_compatibility_patch_enabled = true

100

Ruby-on-rails相关问答推荐

使用超级用户角色和未知密码创建与POSTRES用户的连接

使用RubyZip处理大型压缩文件:65535个文件的限制

Rails文档的悲观锁定示例中的争用条件

如何让删除链接响应 Rails 7 中的 turbo_stream 和 html?

Rails 7 共享刺激控制器功能

线程如何在 Web 应用程序中工作?

从 rails 5 迁移到 rails 6

显示每个 rspec 示例的运行时

如何在 Rails 3 中使用 Capybara 单击具有相同文本的第二个链接?

如何在 YAML 中声明带有单引号和双引号的字符串?

查找日期时间与今天匹配的记录 - Ruby on Rails

具有条件的列的计数器缓存?

Rails 3:验证组合值

Ruby如何写入Tempfile

在 Rails 生产中禁用assets资源 缩小

如何在 RSpec 中包含 Rails 助手

Coffeescript ||= 模拟?

用于在多行上链接调用的 Ruby 约定

如何在 Rails 3 中订购包含的元素

Date.current 和 Date.today 有什么区别?