Class: Dbconsole::DatabasesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/dbconsole/databases_controller.rb', line 76

def create
  @class_name_org = params[:tablename]
  @class_name= params[:tablename].capitalize.singularize.camelize.constantize
  
  @col_names= @class_name.column_names
  @tabinst = @class_name.new
  @col_names.each_with_index do | col_name, index|
    @tabinst[col_name] = params[col_name]
  end
  
  if @tabinst.save
    flash[:notice] = "Record successfully inserted and id is "+@tabinst.id.to_s
  else
    flash[:notice] = "Record not successfully inserted"
  end
 
  redirect_to({ :action=>'show', :id => params[:tablename] })
end

#destroyObject



63
64
65
66
67
68
69
70
# File 'app/controllers/dbconsole/databases_controller.rb', line 63

def destroy
  @class_name = params[:tablename].capitalize.singularize.camelize.constantize
  if @class_name.delete(params[:recordid].to_i) == 1
    flash[:notice] = "Record successfully deleted"
  end
  
  redirect_to({ :action=>'show', :id => params[:tablename] })
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/dbconsole/databases_controller.rb', line 5

def index
  #env = ENV["RAILS_ENV"]
  
  @tables =  ActiveRecord::Base.connection.tables
  @tables.delete_if {|value| value == "schema_migrations" }
  
  #@connection = ActiveRecord::Base.establish_connection(
   #     :adapter => "sqlite3",
    #    :database => "db/development.sqlite3",
  #)
  
  #@tables = @connection.connection.tables
  
  #ActiveRecord::Base.connection.tables.map do |model|
    #puts model.capitalize.singularize.camelize
  #end
  
  #sql = "SHOW TABLES"
  #@result = @connection.connection.execute(sql);
  #@result.each(:as => :hash) do |row| 
   #  puts row
  #end
  
  respond_to do |format|
    format.html # index.html.erb
    #format.json { render json: @tables }
  end
end

#showObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/dbconsole/databases_controller.rb', line 34

def show
  @colinfo = Hash.new("")
  @colidinfo = Hash.new("")
  
  @tables =  ActiveRecord::Base.connection.tables
  
  @tables.delete_if {|value| value == "schema_migrations" }
  
  conn = ActiveRecord::Base.connection
  
  @class_name_org = params[:id]
  @class_name= params[:id].capitalize.singularize.camelize.constantize
  
  @col_names= @class_name.column_names
  @col_names.each_with_index do | col_name, index|
    @colinfo[col_name] = @class_name.columns_hash[col_name].type
    @colidinfo[index] = col_name
  end
  
  @records = conn.execute("select * from "+params[:id])
  #@records =@class_name.all
  puts @records
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @records }
  end
end

#updateObject



72
73
74
# File 'app/controllers/dbconsole/databases_controller.rb', line 72

def update
  
end