Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActiveAdmin/Formtastic自定义输入(JSON)_Ruby On Rails_Json_Activeadmin_Formtastic_Jsonb - Fatal编程技术网

Ruby on rails ActiveAdmin/Formtastic自定义输入(JSON)

Ruby on rails ActiveAdmin/Formtastic自定义输入(JSON),ruby-on-rails,json,activeadmin,formtastic,jsonb,Ruby On Rails,Json,Activeadmin,Formtastic,Jsonb,我的数据库中有一个json列(实际上是jsonb,但在这里这并不重要)表items,只有普通的 { "key1":"value1", "key2":"value2" } 结构。没有筑巢 “键”实际上是指向属性的类似外键的整数 id | name ----------- 1 | Height 2 | Weight 3 | Color 等等 我正在使用ActiveAdmin进行管理,希望在编辑由选择输入和文本字段组成的项目时有一个自定义输入,这将允许我: 从“特性”表中选择特性或输

我的数据库中有一个json列(实际上是jsonb,但在这里这并不重要)表items,只有普通的

{
 "key1":"value1",
 "key2":"value2"
} 
结构。没有筑巢

“键”实际上是指向属性的类似外键的整数

id | name
-----------
1  | Height
2  | Weight
3  | Color
等等

我正在使用ActiveAdmin进行管理,希望在编辑由选择输入和文本字段组成的项目时有一个自定义输入,这将允许我:

  • 从“特性”表中选择特性或输入新特性,然后
  • 在文本字段中键入JSON
我想不出是怎么回事


我尝试过什么?我的问题是什么

我在app/inputs/property_input.rb中创建了一个自定义输入:

class PropertyInput
    include Formtastic::Inputs::Base
    include Formtastic::Inputs::Base::Collections

    def to_html
        input_wrapping do
            label_html <<
            select_html <<
            text_html    
        end
    end

protected

    def select_html
        builder.select(input_name, collection, input_options, input_html_options)
    end

        include Formtastic::Inputs::Base::Stringish
        include Formtastic::Inputs::Base::Placeholder

    def text_html
        builder.text_field(input_name)
    end

end

我的问题是:

现在,select正确地显示属性的名称,但文本字段仅显示相同属性的id。如何解耦这两个字段并强制文本字段保存和读取itemJSONB列

在本例中,我不使用项目和属性模型之间的ActiveRecord关联,因为我不确定它是否适用于包含“外键”的jsonb列,这一点可能很重要

f.input :property, as: :property, collection: ItemAttribute.all