5

I have a collection of articles I want to show in my json response. I would also like to export a node about the type of json request asked.

index.json.rabl

collection @articles => :headlines
extends 'articles/show'

show.json.rabl

object @article
attributes :foo

So going to articles.json gives me:

 {"headlines":[{"foo":thing1},{"foo":thing2}]}

What I would like to do is get results like this:

{"rss":{"name":"articles","woot":"what?"},
{"headlines":[{"foo":thing1},{"foo":thing2}]}

I have tried putting node(:rss) { "yadda yadda" } in the index.json.rabl file, but that only adds the node :rss into the each article.

I tried using

 glue @article do
    node(:rss) { "yadda yadda" }
 end

in both the index and show files and neither worked as I was hoping.

I have tried numerous other things, but at this point I am only guess now.

Community
  • 1
  • 1
Aaron Thomas
  • 505
  • 1
  • 6
  • 18

1 Answers1

9

Ah... I figure it out. I decided not to use "collection @articles"

index.json.rabl

object false
node(:rss) { partial('articles/rss.json.rabl', :object => @feedName) }

node :headlines do
  partial(@jsonView, :object => @articles)
end
Community
  • 1
  • 1
Aaron Thomas
  • 505
  • 1
  • 6
  • 18
  • what is the @jsonView variable? I'm running into a similar problem. – Leo Correa Dec 03 '12 at 19:12
  • Probably just a string that names which partial he wants to render (one with more or less detail for example), perhaps decided on some part of the query params. e.g. `/articles.json => @jsonView = "articles/light", /articles.json?detailed=true => @jsonView = "article/detailed"` – Soup Jan 31 '13 at 05:31