Class: RailsDb::TablesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RailsDb::TablesController
- Defined in:
- app/controllers/rails_db/tables_controller.rb
Constant Summary collapse
- LOAD_TABLE_ACTIONS =
[:show, :data, :csv, :truncate, :destroy, :edit, :update, :xlsx, :search, :new, :create]
Instance Method Summary collapse
- #create ⇒ Object
- #csv ⇒ Object
- #data ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #truncate ⇒ Object
- #update ⇒ Object
- #xlsx ⇒ Object
Instance Method Details
#create ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/rails_db/tables_controller.rb', line 18 def create unless RailsDb.sandbox @record = model.new(record_attributes) @record.save! end build_search respond_to do |page| page.html { redirect_to action: :data, table_id: params[:table_id] } page.js {} end end |
#csv ⇒ Object
40 41 42 |
# File 'app/controllers/rails_db/tables_controller.rb', line 40 def csv send_data(@table.to_csv, type: 'text/csv; charset=utf-8; header=present', filename: "#{@table.name}.csv") end |
#data ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/controllers/rails_db/tables_controller.rb', line 31 def data session[:per_page] = per_page build_search respond_to do |page| page.html {} page.js {} end end |
#destroy ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/rails_db/tables_controller.rb', line 59 def destroy build_search unless RailsDb.sandbox @table.delete(params[:pk_id]) end respond_to do |page| page.html { redirect_to action: :data, table_id: params[:table_id] } page.js {} end end |
#edit ⇒ Object
72 73 74 75 76 77 78 |
# File 'app/controllers/rails_db/tables_controller.rb', line 72 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
7 8 9 |
# File 'app/controllers/rails_db/tables_controller.rb', line 7 def index @tables = RailsDb::Database.accessible_tables end |
#new ⇒ Object
14 15 16 |
# File 'app/controllers/rails_db/tables_controller.rb', line 14 def new @record = model.new end |
#show ⇒ Object
11 12 |
# File 'app/controllers/rails_db/tables_controller.rb', line 11 def show end |
#truncate ⇒ Object
52 53 54 55 56 57 |
# File 'app/controllers/rails_db/tables_controller.rb', line 52 def truncate unless RailsDb.sandbox @table.truncate end render :data end |
#update ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/rails_db/tables_controller.rb', line 80 def update @record = @table.as_model.find(params[:pk_id]) unless RailsDb.sandbox @record.update(record_attributes) end respond_to do |page| page.html { redirect_to action: :data, table_id: params[:table_id] } page.js {} end end |
#xlsx ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/controllers/rails_db/tables_controller.rb', line 44 def xlsx if defined? Axlsx render xlsx: 'table', filename: "#{@table.name}.xlsx" else raise 'RailsDb could not find Axlsx, please add it to your Gemfile: "gem \'caxlsx_rails\'"' end end |