Class: RailsDb::SqlController

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

Instance Method Summary collapse

Instance Method Details

#csvObject



16
17
18
# File 'app/controllers/rails_db/sql_controller.rb', line 16

def csv
  send_data(@sql_query.to_csv, type: 'text/csv; charset=utf-8; header=present', filename: 'results.csv')
end

#executeObject



12
13
14
# File 'app/controllers/rails_db/sql_controller.rb', line 12

def execute
  render :index
end

#importObject



24
25
# File 'app/controllers/rails_db/sql_controller.rb', line 24

def import
end

#import_startObject



27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/rails_db/sql_controller.rb', line 27

def import_start
  @importer = SqlImport.new(params[:file])
  result    = @importer.import
  if result.ok?
    flash[:notice] = 'File was successfully imported'
  else
    flash[:alert] = "Error occurred during import: #{result.error.message}"
  end
  render :import
end

#indexObject



9
10
# File 'app/controllers/rails_db/sql_controller.rb', line 9

def index
end

#xlsObject



20
21
22
# File 'app/controllers/rails_db/sql_controller.rb', line 20

def xls
  render xlsx: 'xls', filename: 'results.xlsx'
end