def escape_object_for_js(object, i = 0)

      if object.kind_of? Hash
        # Recursive case
        Hash.new.tap do |h|
          object.each do |k, v|
            h[escape_object_for_js(k, i + 1)] = escape_object_for_js(v, i + 1)
          end
        end

      elsif object.kind_of? Enumerable
        # Recursive case
        object.map do |elt|
          escape_object_for_js(elt, i + 1)
        end

      elsif object.respond_to? :iso8601
        # Base case - safe object
        object.iso8601

      elsif object.kind_of?(Numeric)
        # Base case - safe object
        object

      elsif [true, false, nil].member?(object)
        # Base case - safe object
        object

      else
        # Base case - use string sanitizer from ActiveSupport
        escape_javascript(object.to_s)

      end
    end
def escape_object_for_js(object, i = 0)

      if object.kind_of? Hash
        # Recursive case
        Hash.new.tap do |h|
          object.each do |k, v|
            h[escape_object_for_js(k, i + 1)] = escape_object_for_js(v, i + 1)
          end
        end

      elsif object.kind_of? Enumerable
        # Recursive case
        object.map do |elt|
          escape_object_for_js(elt, i + 1)
        end

      elsif object.respond_to? :iso8601
        # Base case - safe object
        object.iso8601

      elsif object.kind_of?(Numeric)
        # Base case - safe object
        object

      elsif [true, false, nil].member?(object)
        # Base case - safe object
        object

      else
        # Base case - use string sanitizer from ActiveSupport
        escape_javascript(object.to_s)

      end
    end
Recursively escape anything in a primitive, array, or hash, in
 preparation for jsonifying it