Sha256: 3abdb2ec5a24860b7b975f2c4777f007064aed725ee87ad096e657d5be2404bc
Contents?: true
Size: 978 Bytes
Versions: 14
Compression:
Stored size: 978 Bytes
Contents
module RailsDb class SqlController < RailsDb::ApplicationController if Rails::VERSION::MAJOR >= 4 before_action :load_query, only: [:index, :execute, :csv, :xls] else before_filter :load_query end def index end def execute render :index end def csv send_data(@sql_query.to_csv, type: 'text/csv; charset=utf-8; header=present', filename: 'results.csv') end def xls render xlsx: 'xls', filename: 'results.xlsx' end def import end 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 private def load_query @sql = "#{params[:sql]}".strip @sql_query = RailsDb::SqlQuery.new(@sql).execute end end end
Version data entries
14 entries across 14 versions & 1 rubygems