Rails edit serialized JSON data

I have a column that stores JSON data. I do not know how to show this when it is in an editing state.

serialize :value, JSON = f.fields_for :value do |ff| .form-group = ff.label :short = ff.text_field :short, class: 'form-control' .form-group = ff.label :long = ff.text_field :long, class: 'form-control' 
+5
source share
1 answer

Instead

= f.fields_for :value do |ff|

use the following code:

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

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

+24
source

Source: https://habr.com/ru/post/1203690/


All Articles