我正在尝试在Rails 3.2的rake任务中将rabl视图渲染为字符串。我将其渲染为字符串,以便从后台任务通过Pusher发送一些JSON。我已经查看了各种来自rake任务的render_to_string答案,但似乎没有一个能够工作。到目前为止,这是我的代码:
controller = PostsController.new
av = ActionView::Base.new(MyApp::Application.config.paths['app/views'].first,{},controller)
@post = post
Pusher["some channel"].trigger('new_post', av.render(:template => 'posts/show.json.rabl'))
我尝试使用这个方法,但是出现了一个ActionView::Template::Error例外,错误信息为“未定义的方法`parameters' for nil:NilClass”。