简体   繁体   English

CSV导出自定义

[英]CSV export customization

I have the following piece of code which export a csv file. 我有以下代码导出一个csv文件。

  - if @product.type_id == 2
= "#{l(:user)} ID , #{l(:name)} , #{l(:company)} , #{l(:item)} , #{l(:total)} , #{l(:order_time_stamp)}"
- orders = @product.orders
- orders.each do |order|
  - order_users = get_user_who_order order
  - order_users.each do  |order_user|
    - user = order_user[:user]
    - products , op_total = get_products_and_total order_user[:order_products]
    - company = user.company.present?  ? user.company.name : ''
    - products = products.join('. ')

But we have list of items which is currently rendering in a single column however we need it to be in the different columns like item1, item2, item3 and so on. 但是我们有当前在单个列中呈现的项目列表,但是我们需要将其放在不同的列中,例如item1,item2,item3等。

Seems a bit crazy to me to do this with haml. 我对haml这样做有点疯狂。 There is a nice CSV library in Ruby you can use for this instead. Ruby中有一个不错的CSV库,您可以使用它来代替。

If you still insist on doing it with haml what you are missing is printing the extra , - you need to this yourself when using haml like this. 如果你仍然坚持与HAML你缺的是打印额外的做, -使用HAML这样当你需要自己动手。 I don't see any = in your loop at all. 我在您的循环中根本看不到= How is it possible that you get anything printed at all? 您怎么可能完全打印出任何东西? (Except the header?) (标题除外)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM