iamspauljamez iamspauljamez - 7 months ago 96
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'


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.