Module: Gluttonberg::Content::ImportExportCSV::ClassMethods::ImportExportHelpers::ClassMethods

Defined in:
lib/gluttonberg/content/import_export_csv.rb

Defined Under Namespace

Classes: GlosentryHelper

Instance Method Summary collapse

Instance Method Details

#exportCSV(all_records, local_options = {}) ⇒ Object

sample local_options

:import_columns => [:name, :face_id, :handwritting_id], 
:wysiwyg_columns => [:bio]



71
72
73
# File 'lib/gluttonberg/content/import_export_csv.rb', line 71

def exportCSV(all_records , local_options = {})
  ExportUtils.export(all_records, local_options, self)
end

#helperObject



62
63
64
# File 'lib/gluttonberg/content/import_export_csv.rb', line 62

def helper
  @h ||= GlosentryHelper.new
end

#importCSV(file_path, local_options = {}) ⇒ Object

takes complete path to csv file. if all records are created successfully then return true otherwise returns array of feedback. each value represents the feedback for respective row in csv sample feedback array : [true , true , [active_record error array…] , true] sample local_options

:import_columns => [:name, :face_id, :handwritting_id], 
:wysiwyg_columns => [:bio],
:unique_key => :name,
:additional_attributes => {

}



47
48
49
50
51
52
53
54
55
# File 'lib/gluttonberg/content/import_export_csv.rb', line 47

def importCSV(file_path , local_options = {})
  begin
    require 'csv'
    csv_table = CSV.read(file_path, "r:UTF-8")
  rescue => e
    return "Please provide a valid CSV file with correct column names."
  end
  ImportUtils.import(file_path, local_options, self, csv_table)
end