Class: RailsDb::TablesController

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

Instance Method Summary collapse

Instance Method Details

#csvObject



21
22
23
24
# File 'app/controllers/rails_db/tables_controller.rb', line 21

def csv
  @table = RailsDb::Table.new(params[:table_id])
  send_data(@table.to_csv, type: 'text/csv; charset=utf-8; header=present', filename: "#{@table.name}.csv")
end

#dataObject



12
13
14
15
16
17
18
19
# File 'app/controllers/rails_db/tables_controller.rb', line 12

def data
  per_page = params[:per_page] || session[:per_page]
  session[:per_page] = per_page
  @table   = RailsDb::Table.new(params[:table_id]).paginate page: params[:page],
                                                            sort_column: params[:sort_column],
                                                            sort_order: params[:sort_order],
                                                            per_page: per_page
end

#destroyObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/rails_db/tables_controller.rb', line 32

def destroy
  @table = RailsDb::Table.new(params[:table_id]).paginate page: params[:page],
                                                          sort_column: params[:sort_column],
                                                          sort_order: params[:sort_order],
                                                          per_page: session[:per_page]
  @table.delete(params[:pk_id])
  respond_to do |page|
    page.html { redirect_to action: :data, table_id: params[:table_id] }
    page.js {}
  end
end

#indexObject



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

def index
  @tables = RailsDb::Database.accessible_tables
end

#showObject



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

def show
  @table = RailsDb::Table.new(params[:id])
end

#truncateObject



26
27
28
29
30
# File 'app/controllers/rails_db/tables_controller.rb', line 26

def truncate
  @table = RailsDb::Table.new(params[:table_id])
  @table.truncate
  render :data
end