Rails 3: How to respond_with csv without having a template file?

后端 未结 6 2360
时光取名叫无心
时光取名叫无心 2020-12-28 17:29

I have an object that has a to_csv method and I want to pass it to respond_with to render csv from my controller. My code looks like this:

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 17:40

    I think your model would have to have a to_csv method that returns the attributes as csv.

    After that, if Rails doesn't call the to_csv method implicitly, I would try

    respond_with TripReport.new.to_csv
    

提交回复
热议问题