CSV导入-带有确认-标准溶液/宝石? [英] CSV import - with confirmation - standard solution/gem?

查看:108
本文介绍了CSV导入-带有确认-标准溶液/宝石?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我希望允许用户上传CSV文件,然后向其显示映射到我的列的数据视图,以便用户可以确认其数据正确.理想情况下,允许他们编辑不正确的数据.

In my application I wish to allow the user to upload a CSV file and then be presented with a view of their data mapped to my columns so that the user can confirm their data is correct. Ideally allowing them to edit incorrect data.

是否存在通过gem,任何其他标准解决方案或任何可能有助于实现我想要实现的资源的解决方案.

Are there any existing solutions to this via a gem, any other standard solution or any resources that might help with what I want to achieve.

非常感谢您的帮助.

推荐答案

您可以执行以下操作:

require 'csv'

file_content = File.read(params[:file].tempfile.path)
csv = CSV.parse(file_content, :headers => true)
File.unlink(params[:file].tempfile.path)

取决于传递给控制器​​的参数,但是CVS可以解析通常上传到tmp目录中的文件,结果的显示取决于您的视图层

depends on your params passed to the controller, but CVS can parse a file which is usually written to a tmp dir if uploaded, presentation of the result is up to your view layer

这篇关于CSV导入-带有确认-标准溶液/宝石?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆