Class: RailsDb::TablesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RailsDb::TablesController
- Defined in:
- app/controllers/rails_db/tables_controller.rb
Instance Method Summary collapse
- #csv ⇒ Object
- #data ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #truncate ⇒ Object
- #update ⇒ Object
- #xlsx ⇒ Object
Instance Method Details
#csv ⇒ Object
30 31 32 |
# File 'app/controllers/rails_db/tables_controller.rb', line 30 def csv send_data(@table.to_csv, type: 'text/csv; charset=utf-8; header=present', filename: "#{@table.name}.csv") end |
#data ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/rails_db/tables_controller.rb', line 16 def data session[:per_page] = per_page @model = @table.as_model @q = @model.ransack(params[:q]) @sql = @q.result.page(params[:page]).per(per_page).to_sql @records = @q.result.page(params[:page]).per(per_page) @q.build_condition if @q.conditions.empty? @q.build_sort if @q.sorts.empty? respond_to do |page| page.html {} page.js {} end end |
#destroy ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/rails_db/tables_controller.rb', line 43 def destroy @model = @table.as_model @q = @model.ransack(params[:q]) @sql = @q.result.page(params[:page]).per(per_page).to_sql @records = @q.result.page(params[:page]).per(per_page) @q.build_condition if @q.conditions.empty? @q.build_sort if @q.sorts.empty? @table.delete(params[:pk_id]) respond_to do |page| page.html { redirect_to action: :data, table_id: params[:table_id] } page.js {} end end |
#edit ⇒ Object
57 58 59 60 61 62 63 |
# File 'app/controllers/rails_db/tables_controller.rb', line 57 def edit @record = @table.as_model.find(params[:pk_id]) respond_to do |page| page.html { redirect_to action: :data, table_id: params[:table_id] } page.js {} end end |
#index ⇒ Object
9 10 11 |
# File 'app/controllers/rails_db/tables_controller.rb', line 9 def index @tables = RailsDb::Database.accessible_tables end |
#show ⇒ Object
13 14 |
# File 'app/controllers/rails_db/tables_controller.rb', line 13 def show end |
#truncate ⇒ Object
38 39 40 41 |
# File 'app/controllers/rails_db/tables_controller.rb', line 38 def truncate @table.truncate render :data end |
#update ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/controllers/rails_db/tables_controller.rb', line 65 def update @record = @table.as_model.find(params[:pk_id]) @record.update_attributes(record_attributes) respond_to do |page| page.html { redirect_to action: :data, table_id: params[:table_id] } page.js {} end end |
#xlsx ⇒ Object
34 35 36 |
# File 'app/controllers/rails_db/tables_controller.rb', line 34 def xlsx render xlsx: 'table', filename: "#{@table.name}.xlsx" end |