Business intelligence made simple
Set tables in controller
Andrew Kane13385191312b
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rbindex d22b1be5..85f715b1 100644--- a/app/controllers/blazer/queries_controller.rb+++ b/app/controllers/blazer/queries_controller.rb@@ -13,6 +13,7 @@ module Blazerbefore_action :ensure_database_urlbefore_action :set_query, only: [:show, :edit, :update, :destroy]+ before_action :set_tables, only: [:new, :edit]def index@queries = Blazer::Query.order(:name).includes(:creator)@@ -135,6 +136,10 @@ module Blazer@query = Blazer::Query.find(params[:id].to_s.split("-").first)end+ def set_tables+ @tables = tables+ end+def query_paramsparams.require(:query).permit(:name, :description, :statement)end@@ -213,7 +218,6 @@ module Blazerrows, error = run_statement(Blazer::Connection.send(:sanitize_sql_array, ["SELECT table_name, column_name, ordinal_position, data_type FROM information_schema.columns WHERE table_schema = ?", schema]))Hash[ rows.group_by{|r| r["table_name"] }.map{|t, f| [t, f.sort_by{|f| f["ordinal_position"] }.map{|f| f.slice("column_name", "data_type") }] }.sort_by{|t, f| t } ]end- helper_method :tablesendenddiff --git a/app/views/blazer/queries/_form.html.erb b/app/views/blazer/queries/_form.html.erbindex 28dc311d..7e9c46ca 100644--- a/app/views/blazer/queries/_form.html.erb+++ b/app/views/blazer/queries/_form.html.erb@@ -16,7 +16,7 @@<%= link_to "Back", :back %><span class="text-muted" style="margin-left: 20px;"> Use {start_time} and {end_time} for time ranges</span></div>- <%= select_tag :table_names, options_for_select([["Preview table", nil]] + tables.keys), style: "margin-right: 20px; width: 240px;" %>+ <%= select_tag :table_names, options_for_select([["Preview table", nil]] + @tables.keys), style: "margin-right: 20px; width: 240px;" %><%= link_to "Run", "#", class: "btn btn-info", id: "run", style: "vertical-align: top;" %></div></div>