I am trying to create a json file from a rake task using rabl. Below I have a simplified version for testing.
When I look through 'articles.json' or 'articles / 2.json' via url, I get the expected json response.
But when I try to run it with the rake command, it is always null for @articles in the generated jsonFile. It will show index.json.rabl as many times as @ articles.count, but the values are always zero.
So, how do I pass the @articles object created in my rake command 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
source
share