Created
September 28, 2011 16:46
-
-
Save jonpaul/1248451 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
= f.input :mapping_#{somehow_indicate_this_is_@import_header[0]}, :as => :select, :collection => @mdm_defaults | |
%span= import_headers |
This file contains hidden or 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 map_listing | |
@mdm_defaults = Listing::MDM_DEFAULTS | |
file_field = params[:map_listing][:file] | |
session[:map_fields] = {} | |
temp_path = File.join(Dir::tmpdir, "map_fields_#{Time.now.to_i}_#{$$}") | |
File.open(temp_path, 'wb') do |f| | |
f.write file_field.read | |
end | |
session[:map_fields][:file] = temp_path | |
CSV.foreach(session[:map_fields][:file], { :headers => true, :return_headers => true }) do |row| | |
@import_headers = row if row.header_row? | |
end | |
new_array = [] | |
@import_headers.to_hash.each_key {|k| new_array << k} | |
@import_headers = new_array.compact!.collect {|h| h.downcase.tr(" ", "_").delete("^a-z0-9_").to_sym} | |
session[:map_fields][:imported_headers] = @import_headers | |
render | |
end |
This file contains hidden or 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
- title "Map and Import Headers" | |
= semantic_form_for :listing, :url => listings_path, :method => :post do |f| | |
%ul#mappings= render :partial => 'import_headers', :collection => @import_headers, :locals => {:f => f} | |
= f.buttons |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment