Last active
October 1, 2017 16:13
-
-
Save raresloth/1332d52fd643f4fe0c302882484f161c to your computer and use it in GitHub Desktop.
Quick setup for importing a csv on a Rails server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def import_csv | |
if params[:file] | |
ImportHelper.import_csv(params[:file]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.import_csv(file) | |
CSV.parse(File.read(file.path), headers: true) do |row| | |
# Do stuff | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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