分组选择输入的自定义名称

问题描述

我正在使用一个简单的表单,并且我已经为集合字段提供了一个 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>regitry</groupId> <artifactId>WebApp</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <project.builder.sourceEncoding>UTF-8</project.builder.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>11</source> <target>11</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-api</artifactId> <version>8.0.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.derby</groupId> <artifactId>derbyclient</artifactId> <version>10.15.2.0</version> </dependency> </dependencies> 。我的数据库架构中不存在该名称,我也不想保存它,我只是将它用作参考以填充另一个字段。我就是这样做的:

custom_name

现在我想将集合字段输入更改为分组选择字段,如下所示:

<%= f.input :custom_name,as: :fake_select,collection: Category.roots,input_html: { id: 'first-dropdown' } %>

app/inputs/fake_select_input.rb
class FakeSelectInput < SimpleForm::Inputs::CollectionSelectInput
  def input(wrapper_options = nil)
    label_method,value_method = detect_collection_methods

    merged_input_options = merge_wrapper_options(input_html_options,wrapper_options).merge(input_options.slice(:multiple,:include_blank,:disabled,:prompt))

    template.select_tag(
      attribute_name,template.options_from_collection_for_select(collection,value_method,label_method,selected: input_options[:selected],disabled: input_options[:disabled]),merged_input_options
    )
  end
end

但是我在使用新的分组选择输入时遇到此错误

 <%= f.input : custom_name,collection: @categories.order(:name),as: :grouped_select,group_method: :children,label: false,:include_blank => "--Select Category--",input_html: { id: "first_dropdown" } %>

关于如何使用 undefined method `custom_name' for #<Product:0x00007f98d4dcf950> 传递分组的选择输入的任何想法?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)