fix editable + serialized-hash attributes
authorTom Clegg <tom@clinicalfuture.com>
Thu, 27 Jun 2013 16:35:35 +0000 (12:35 -0400)
committerTom Clegg <tom@clinicalfuture.com>
Thu, 27 Jun 2013 16:35:35 +0000 (12:35 -0400)
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/helpers/application_helper.rb

index 3cae2dcbd7021a164da41f583049584be632939d..3da3faadccbc0e5f943cf82d7e459a2ba4c7d148 100644 (file)
@@ -77,7 +77,13 @@ class ApplicationController < ActionController::Base
   end
 
   def update
-    if @object.update_attributes params[@object.class.to_s.underscore.singularize.to_sym]
+    updates = params[@object.class.to_s.underscore.singularize.to_sym]
+    updates.keys.each do |attr|
+      if @object.send(attr).is_a? Hash and updates[attr].is_a? String
+        updates[attr] = Oj.load updates[attr]
+      end
+    end
+    if @object.update_attributes updates
       show
     else
       self.render_error status: 422
index 9a9be45e54ea14e009f2416d6140a70754c2d341..049326b26ff2be45d2c12ff9ec2a0e8340f68571 100644 (file)
@@ -49,13 +49,14 @@ module ApplicationHelper
       input_type = 'text'
     end
 
+    attrvalue = attrvalue.to_json if attrvalue.is_a? Hash
+
     link_to attrvalue.to_s, '#', {
       "data-emptytext" => "none",
       "data-placement" => "bottom",
       "data-type" => input_type,
       "data-resource" => object.class.to_s.underscore,
       "data-name" => attr,
-      "data-value" => object.send(attr),
       "data-url" => url_for(action: "update", id: object.uuid, controller: object.class.to_s.pluralize.underscore),
       "data-original-title" => "Update #{attr.gsub '_', ' '}",
       :class => "editable"