Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (38 sloc) 1.32 KB

Argonaut is a lightweight JSON builder template handler for Rails

Installing it

It’s as easy as:

script/plugin install git://


It’s a whole lot like .xml.builder, only it’s .json.argonaut. Make an appropriately named view, like show.json.argonaut and put something in it like:

for idea in @ideas
  doc.ideas do |i|
    i.title idea.title
    for comment in idea.comments
      i.comments do |c|
        c.text comment.text

Which is identical to

  :ideas => do |idea|
      :title => idea.title,
      :comments => do |comment|
          :author =>,
          :text => comment.text

Just a little code kata, not really sure that the former is actually prettier.

XML too

The name makes less sense and it’s not really better than Builder, but you can do .xml.argonaut as well now. It’s the equivalent of calling to_xml(:root => 'response') on the above hash. In theory, the same file could be used for .xml.argonaut and .json.argonaut, but it’s not obvious how to tell the template handler system to reuse a template. Maybe soon.

Jump to Line
Something went wrong with that request. Please try again.