Friday 9 August 2013

nesting another field in a json column

nesting another field in a json column

I'm trying to use the Json type available in the Postgres 9.2 release as a
means to . I created a column called data on the corrections table, and
when I present the corrections form I'm also passing the text_field
content so that when I create an entry it will be saved like this
data: {"content from @content"=>"value entered in form field", "content
from @content" => "value entered in form field }
with the multiple entries with (dynamic key names) in data resulting from
however many form fields are created by <% @content.each do |content| %>
in the form below.
<% @content.each do |content| %>
<div class="row">
<p class='span3'>
<%= label_tag(content, "#{content}") %>
</p>
<p class='span3'>
<%= d.text_area content, :class => 'content', :value => "", :cols
=> "40", :rows => "2", :id =>
'correction_data_'"#{content.parameterize}"%>
I have two questions
1 How would I change the Rails form to nest another key value pair inside
(or associate with) each
"content from @content"=>"value entered in form field"
2 Is this proper JSON format? It seems to me like it's just saving a bunch
of key value pairs with the key always changing depending on the content
from @content. If it isn't, is that a problem? Am I missing out on
something by doing it this way?
data: {"content from @content"=>"value entered in form field", "content
from @content" => "value entered in form field }

No comments:

Post a Comment