Class: RailsDb::SqlController

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

Instance Method Summary collapse

Instance Method Details

#csvObject



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

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

#executeObject



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

def execute
  render :index
end

#importObject



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

def import
end

#import_startObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/rails_db/sql_controller.rb', line 23

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



5
6
# File 'app/controllers/rails_db/sql_controller.rb', line 5

def index
end

#xlsObject



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

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