iamspauljamez iamspauljamez - 1 year ago 234
JSON Question

Rails edit serialized JSON data

I have a column that stores JSON data. I don't know how to show it when it is on Edit state.

serialize :value, JSON

= f.fields_for :value do |ff|
= ff.label :short
= ff.text_field :short, class: 'form-control'
= ff.label :long
= ff.text_field :long, class: 'form-control'

Answer Source

In place of

= f.fields_for :value do |ff|

please use the following code:

= f.fields_for :value, OpenStruct.new(@object.value) do |ff|

You will need to replace @object with your model object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download