Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
csv import example in model
# controller
def proc_csv
import = Import.find(params[:id])
if import.load_csv
flash[:notice] = "woo"
redirect_to some_url
else
flash[:error] = "ohoh"
end
end
# model
def load_csv
file = "path_to_file"
parsed_file = FasterCSV.read(file, :headers => true)
parsed_file.each do |row|
new_release = {
:title => row[0],
:rdate => row[1],
:body => row[2],
:notes => row[3]
}
release = Release.new(new_release)
release.save!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.