Skip to content

Instantly share code, notes, and snippets.

@raresloth
Last active October 1, 2017 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raresloth/1332d52fd643f4fe0c302882484f161c to your computer and use it in GitHub Desktop.
Save raresloth/1332d52fd643f4fe0c302882484f161c to your computer and use it in GitHub Desktop.
Quick setup for importing a csv on a Rails server
def import_csv
if params[:file]
ImportHelper.import_csv(params[:file])
end
end
<%= form_tag import_path, multipart: true do %>
<div class="form-group">
<%= file_field_tag :file %>
</div>
<div class="actions">
<%= submit_tag "Import", {class: "btn btn-primary"} %>
</div>
<% end %>
def self.import_csv(file)
CSV.parse(File.read(file.path), headers: true) do |row|
# Do stuff
end
end
get 'import', to: 'import#import'
post 'import', to: 'import#import'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment