nesquena / rabl

General ruby templating with json, bson, xml, plist and msgpack support
http://blog.codepath.com/2011/06/27/building-a-platform-api-on-rails/
MIT License
3.65k stars 335 forks source link

How to skip json_escape for strings? #472

Open ExReanimator opened 11 years ago

ExReanimator commented 11 years ago

Controller:

def create
    @status = 0
    @errors = Array.new

    if @user.save
      @status = 1
    else
      @user.errors.full_messages.each { |e| @errors << e }
    end
end

View (create.json.rabl):

object false

node(:status) {|m| @status }

if @errors.any?

  child @errors => :errors do
    extends "error"
  end

end

partial "_error":

object @errors

node(:text) { |e| e }

Result

=> "{\"status\":0,\"errors\":[{\"error\":{\"text\":\"\xD0\x9F\xD0\xB0\xD1\x80\xD0\xBE\xD0\xBB\xD1\x8C \xD0\xBD\xD0\xB5 \xD0\xBC\xD0\xBE\xD0\xB6\xD0\xB5\xD1\x82 \xD0\xB1\xD1\x8B\xD1\x82\xD1\x8C \xD0\xBF\xD1\x83\xD1\x81\xD1\x82\xD1\x8B\xD0\xBC\"}},{\"error\":{\"text\":\"\xD0\x9F\xD0\xBE\xD0\xB4\xD1\x82\xD0\xB2\xD0\xB5\xD1\x80\xD0\xB6\xD0\xB4\xD0\xB5\xD0\xBD\xD0\xB8\xD0\xB5 \xD0\xBF\xD0\xB0\xD1\x80\xD0\xBE\xD0\xBB\xD1\x8F \xD0\xBD\xD0\xB5 \xD0\xBC\xD0\xBE\xD0\xB6\xD0\xB5\xD1\x82 \xD0\xB1\xD1\x8B\xD1\x82\xD1\x8C \xD0\xBF\xD1\x83\xD1\x81\xD1\x82\xD1\x8B\xD0\xBC\"}}]}"

The problem is that in another rabl templates of my project strings was not decoded to utf symbols. How to disable that?

awinogradov commented 11 years ago

+1 I have this problem too.