Rendering a simple Ruby hash with RABL

SundayMonday picture SundayMonday · Jan 20, 2012 · Viewed 9.7k times · Source

I have a ruby hash that I'd like to render using RABL. The hash looks something like this:

@my_hash = {
    :c => {
        :d => "e"
    }
}

I'm trying to render this with some RABL code:

object @my_hash => :some_object
attributes :d
node(:c) { |n| n[:d] }

but I'm receiving {"c":null}

How can I render this with RABL?

Answer

rharriso picture rharriso · Jun 28, 2013

This works for arbitrary hash values.

object false

@values.keys.each do |key|
  node(key){ @values[key] }
end

Worked for me using Rails 3.2.13 and Ruby 2.0.0-p195