我有一个有一个to_csv方法的对象,我想将它传递respond_with给我的控制器渲染csv.我的代码看起来像这样:
class Admin::ReportsController < AdminController
respond_to :csv
def trips
respond_with TripReport.new
end
end
Run Code Online (Sandbox Code Playgroud)
TripReport的实例具有to_csv方法.
当我向该操作发出请求时,我收到以下错误:
ActionView::MissingTemplate (Missing template admin/reports/trips with {:formats=>[:csv], :handlers=>[:erb, :builder, :rjs, :rhtml, :rxml], :locale=>[:en, :en]} in view paths
Run Code Online (Sandbox Code Playgroud)
所以看起来控制器正在寻找要渲染的模板文件.我怎么能绕过这个?
我宁愿csv格式以类似于json的方式响应,所以它调用to_csv对象并只渲染输出,这可能吗?