Class: Dbviewer::ConnectionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Dbviewer::ConnectionsController
- Defined in:
- app/controllers/dbviewer/connections_controller.rb
Instance Method Summary collapse
-
#index ⇒ Object
GET /dbviewer/connections.
-
#update ⇒ Object
POST /dbviewer/connections/:id.
Methods included from DatabaseOperations
#database_manager, #table_query_operations
Methods included from DatatableSupport
Methods included from DataExport
Methods included from QueryOperations
#default_query, #execute_query, #prepare_query
Methods included from RelationshipManagement
#fetch_mini_erd_for_table, #fetch_table_relationships
Methods included from TableOperations
#fetch_filtered_record_count, #fetch_table_columns, #fetch_table_metadata, #fetch_table_record_count, #fetch_table_records, #fetch_tables, #safe_quote_table_name
Methods included from DatabaseInformation
#fetch_database_analytics, #get_adapter_name, #get_database_name
Methods included from ConnectionManagement
#available_connections, #current_connection_key, #switch_connection
Instance Method Details
#index ⇒ Object
GET /dbviewer/connections
4 5 6 7 8 9 10 11 |
# File 'app/controllers/dbviewer/connections_controller.rb', line 4 def index @connections = available_connections respond_to do |format| format.html format.json { render json: @connections } end end |
#update ⇒ Object
POST /dbviewer/connections/:id
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/dbviewer/connections_controller.rb', line 14 def update connection_key = params[:id] if switch_connection(connection_key) # Safely get the connection name connection_config = Dbviewer.configuration.database_connections[connection_key.to_sym] connection_name = connection_config && connection_config[:name] ? connection_config[:name] : "selected" respond_to do |format| format.html { redirect_to root_path, notice: "Switched to #{connection_name} database." } format.json { render json: { success: true, current: connection_key } } end else # Handle the case where switching failed respond_to do |format| format.html { redirect_to connections_path, alert: "Failed to switch connection. The connection may be invalid." } format.json { render json: { success: false, error: "Invalid connection" }, status: :unprocessable_entity } end end end |