Class: ImportController

Inherits:
ApplicationController show all
Defined in:
app/controllers/import_controller.rb

Instance Method Summary collapse

Instance Method Details

#import_from_fileObject


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/import_controller.rb', line 8

def import_from_file
  file_data = params[:uploaded_file]      
  if file_data.respond_to?(:read)
    @file_content = file_data.read
  elsif file_data.respond_to?(:path)
    @file_content = File.read(file_data.path)
  else
    # logger.error "Bad file_data: #{file_data.class.name}: #{file_data.inspect}"
    flash[:notice] = "Bad file_data: #{file_data.class.name}: #{file_data.inspect}" 
  end  
  create_categories_from_json(@file_content)
  render :index                 
end

#import_from_textObject


30
31
32
33
34
35
# File 'app/controllers/import_controller.rb', line 30

def import_from_text
  @file_content = params[:content]
  create_categories_from_json(@file_content)

  render :index
end

#import_from_urlObject


22
23
24
25
26
27
28
# File 'app/controllers/import_controller.rb', line 22

def import_from_url    
  require 'open-uri'
  @file_content = open(params[:url]).read
  create_categories_from_json(@file_content)

  render :index
end

#indexObject


4
5
6
# File 'app/controllers/import_controller.rb', line 4

def index
  authorize :import, :index?    
end