require_dependency "easy_reports/application_controller" module EasyReports class ReportsController < ApplicationController before_action :set_report, only: [:show, :edit, :update, :destroy] def index @reports = Report.all # TODO: remove into service @old_connection = ActiveRecord::Base.connection db_config = EasyReports::DatabaseConfig.last ActiveRecord::Base.establish_connection( adapter: db_config.adapter, encoding: db_config.encoding, pool: db_config.pool, username: db_config.username, password: db_config.password, host: db_config.host, database: db_config.database ) @table_list = ActiveRecord::Base.connection.tables ActiveRecord::Base.establish_connection("#{Rails.env}") end def show end def new @report = Report.new end def edit end def create @report = Report.new(report_params) if @report.save redirect_to @report, notice: 'Report was successfully created.' else render :new end end def update if @report.update(report_params) redirect_to @report, notice: 'Report was successfully updated.' else render :edit end end def destroy @report.destroy redirect_to reports_url, notice: 'Report was successfully destroyed.' end private def set_report @report = Report.find(params[:id]) end def report_params params.require(:report).permit(:title, :description) end end end