CSV import - with confirmation - standard solution/gem?

こ雲淡風輕ζ 提交于 2019-12-11 17:34:51

问题


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.

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.

Help very much appreciated.


回答1:


you can do something like:

require 'csv'

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

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



来源:https://stackoverflow.com/questions/18498501/csv-import-with-confirmation-standard-solution-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!