Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.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 简单表单未找到json的输入_Ruby On Rails_Json_Postgresql_Simple Form - Fatal编程技术网

Ruby on rails 简单表单未找到json的输入

Ruby on rails 简单表单未找到json的输入,ruby-on-rails,json,postgresql,simple-form,Ruby On Rails,Json,Postgresql,Simple Form,环境 MacOSX Rails 4.0.4 Ruby 2.1.1 宝石: 创建一个带有json类型字段的模型,这里是我的迁移文件: create_table :my_model do |t| t.string :name t.json :my_field t.timestamps end 现在,当我尝试创建一个新对象(新表单)时,我得到了这个错误 RuntimeError - No input found for json: simple_form (3.0.2) lib/

环境 MacOSX Rails 4.0.4 Ruby 2.1.1

宝石:

创建一个带有json类型字段的模型,这里是我的迁移文件:

create_table :my_model do |t|
  t.string :name
  t.json :my_field

  t.timestamps
end
现在,当我尝试创建一个新对象(新表单)时,我得到了这个错误

RuntimeError - No input found for json:
  simple_form (3.0.2) lib/simple_form/form_builder.rb:551:in `find_mapping'
  simple_form (3.0.2) lib/simple_form/form_builder.rb:482:in `find_input'
  simple_form (3.0.2) lib/simple_form/form_builder.rb:111:in `input'
我猜simple_表单不能很好地处理JSON类型,我真的不知道如何解决这个问题(simple_表单新手)


希望您能帮助简单的表单,不支持
JSON
本机输入。但事实证明,JSON是基于文本的数据格式,您可以简单地使用textarea输出JSON

<%= f.my_field, as: :text %>


这应该很好

不要忘记逗号,
您也可以在初始值设定项中放置以下行来定义自定义输入映射

SimpleForm::FormBuilder.map_type :json, to: SimpleForm::Inputs::TextInput