Skip to content

Instantly share code, notes, and snippets.

@janjitsu
Forked from toniesteves/archive_controller.rb
Last active August 28, 2016 00:55
Show Gist options
  • Select an option

  • Save janjitsu/70dcdeae830e84df1cb38e47507fc8d5 to your computer and use it in GitHub Desktop.

Select an option

Save janjitsu/70dcdeae830e84df1cb38e47507fc8d5 to your computer and use it in GitHub Desktop.
def create
@archive = Archive.new(archive_params)
@archive = ArchiveProcessor.new(@archive).process
if @archive.save
redirect_to archives_path, notice: "The resume #{@archive.name} has been uploaded."
else
render "new"
end
end
class ArchiveProcessor
def initialize(archive)
@archive = archive
end
def process
receipt = 0
options = {:col_sep => "\t", :row_sep => "\n"}
SmarterCSV.process(archive_params[:attachment].path,options) do |chunk|
chunk.each do |data_hash|
@archive.receipt += data_hash[:price]
Order.create!( data_hash )
end
end
@archive
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment