I am trying to create a json file from a rake task using rabl. Below I have the simplified version to test with.
When I view 'articles.json' or 'articles/2.json' via the url, I get the expected json response.
But when I try to run it via the rake task, it always has a null value for @articles in the jsonFile created. It will render the index.json.rabl view the same number of times as @articles.count, but the values are always null.
So how do I pass in the @articles object created in my rake task to Rabl.render?
index.json.rabl
@feedName ||= 'default'
node(:rss) { partial('articles/rss), :object => @feedName }
node(:headlines) { partial('articles/show'), :object => @articles }
show.json.rabl
object @article
attributes :id,:body
....
exports.rake
task :breakingnews => :config do
filename = 'breakingnews.json'
jsonFile = File.new(filename)
@articles = Article.limit(10)
n = Rabl::renderer.json(@articles,'articles/index',view_paths => 'app/views')
jsonFile.puts b
jsonFile.close