Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple_form no input found for json

Environment Mac OS X Rails 4.0.4 Ruby 2.1.1

Gems: simple_form

Create a model with a json typed field, here my migration file:

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

  t.timestamps
end

And now when I try to create a New object (New form), I am getting this error

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'

I am guessing that simple_form is not handling the JSON type very well, and I really don't know how to work around this one (newbie with simple_form).

Hope you can help

like image 218
zabumba Avatar asked Apr 14 '14 13:04

zabumba


2 Answers

simple_form, doesn't support JSON type natively. but as it turns out, JSON is text based data format, you can simple use textarea to output json.

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

this should work fine

like image 83
CuriousMind Avatar answered Sep 19 '22 16:09

CuriousMind


Don't forget the comma, <%= f.input, as: :text %>

like image 32
Alex Avatar answered Sep 21 '22 16:09

Alex