Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
like image 875
iamspauljamez Avatar asked Sep 30 '14 08:09

iamspauljamez


1 Answers

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.

like image 186
Manoj Menon Avatar answered Oct 10 '22 09:10

Manoj Menon