Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created June 17, 2011 13:06
Show Gist options
  • Save marshluca/1031377 to your computer and use it in GitHub Desktop.
Save marshluca/1031377 to your computer and use it in GitHub Desktop.
Json Response without escaping in Rails 3
module ActiveSupport
module JSON
module Encoding
def self.escape(string)
if string.respond_to?(:force_encoding)
string = string.encode(::Encoding::UTF_8, :undef => :replace).force_encoding(::Encoding::BINARY)
end
json = string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] }
json = %("#{json}")
json.force_encoding(::Encoding::UTF_8) if json.respond_to?(:force_encoding)
json
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment