Skip to content

Instantly share code, notes, and snippets.

@darrenterhune
Created February 24, 2010 09:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darrenterhune/313281 to your computer and use it in GitHub Desktop.
Save darrenterhune/313281 to your computer and use it in GitHub Desktop.
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