iamspauljamez
iamspauljamez

Reputation: 287

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|
    .form-group
      = ff.label :short  
      = ff.text_field :short, class: 'form-control'
    .form-group
      = ff.label :long
      = ff.text_field :long, class: 'form-control'

Upvotes: 6

Views: 4914

Answers (1)

Manoj Menon
Manoj Menon

Reputation: 1038

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.

Upvotes: 30

Related Questions