I am using Ruby on Rails 3 and I would like, in some way, to convert a string to_json and to_xml.
Just to know, I need to return that string in a Rack method in this way:
[404, {"Content-type" => "application/json"}, ["Bad request"]]
# or
[404, {"Content-type" => "application/xml"}, ["Bad request"]]
However what I need is only to convert that string to_json and to_xml? How is it possible do that?
Sometimes you must add a
require 'json'in your file (after installing the gem, JSON implementation for Ruby ) and do:or you could try:
But in your case maybe the best approach is respond correctly:
Alternatively you could do: