Skip to content

Instantly share code, notes, and snippets.

@jonpaul
Created September 28, 2011 16:46
Show Gist options
  • Save jonpaul/1248451 to your computer and use it in GitHub Desktop.
Save jonpaul/1248451 to your computer and use it in GitHub Desktop.
= f.input :mapping_#{somehow_indicate_this_is_@import_header[0]}, :as => :select, :collection => @mdm_defaults
%span= import_headers
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
- 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