Skip to content

Business intelligence made simple

Fixed creator= error

Andrew Kane08a489281fc4
diff --git a/app/controllers/blazer/checks_controller.rb b/app/controllers/blazer/checks_controller.rb
index 695c314c..912064b0 100644
--- a/app/controllers/blazer/checks_controller.rb
+++ b/app/controllers/blazer/checks_controller.rb
@@ -15,7 +15,7 @@ module Blazer
@check = Blazer::Check.new(check_params)
# use creator_id instead of creator
# since we setup association without checking if column exists
- @check.creator = blazer_user if @check.respond_to?(:creator_id=)
+ @check.creator = blazer_user if @check.respond_to?(:creator_id=) && blazer_user
if @check.save
redirect_to run_check_path(@check)
diff --git a/app/controllers/blazer/dashboards_controller.rb b/app/controllers/blazer/dashboards_controller.rb
index 232c9a9d..e4aa9263 100644
--- a/app/controllers/blazer/dashboards_controller.rb
+++ b/app/controllers/blazer/dashboards_controller.rb
@@ -14,7 +14,7 @@ module Blazer
@dashboard = Blazer::Dashboard.new
# use creator_id instead of creator
# since we setup association without checking if column exists
- @dashboard.creator = blazer_user if @dashboard.respond_to?(:creator_id=)
+ @dashboard.creator = blazer_user if @dashboard.respond_to?(:creator_id=) && blazer_user
if update_dashboard(@dashboard)
redirect_to dashboard_path(@dashboard)
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rb
index 663a261b..b18a32b8 100644
--- a/app/controllers/blazer/queries_controller.rb
+++ b/app/controllers/blazer/queries_controller.rb
@@ -162,7 +162,7 @@ module Blazer
render layout: false
end
format.csv do
- send_data csv_data(@columns, @rows), type: "text/csv; charset=utf-8; header=present", disposition: "attachment; filename=\"#{@query.try(:name).try(:parameterize).presence || 'query'}.csv\""
+ send_data csv_data(@columns, @rows, @data_source), type: "text/csv; charset=utf-8; header=present", disposition: "attachment; filename=\"#{@query.try(:name).try(:parameterize).presence || 'query'}.csv\""
end
end
end
@@ -240,18 +240,17 @@ module Blazer
params.require(:query).permit(:name, :description, :statement, :data_source)
end
- def csv_data(columns, rows)
+ def csv_data(columns, rows, data_source)
CSV.generate do |csv|
csv << columns
rows.each do |row|
- csv << row.each_with_index.map { |v, i| v.is_a?(Time) ? blazer_time_value(columns[i], v) : v }
+ csv << row.each_with_index.map { |v, i| v.is_a?(Time) ? blazer_time_value(data_source, columns[i], v) : v }
end
end
end
- def blazer_time_value(k, v)
- # yuck, instance var
- @data_source.local_time_suffix.any? { |s| k.ends_with?(s) } ? v.to_s.sub(" UTC", "") : v.in_time_zone(Blazer.time_zone)
+ def blazer_time_value(data_source, k, v)
+ data_source.local_time_suffix.any? { |s| k.ends_with?(s) } ? v.to_s.sub(" UTC", "") : v.in_time_zone(Blazer.time_zone)
end
helper_method :blazer_time_value
end
diff --git a/app/views/blazer/queries/run.html.erb b/app/views/blazer/queries/run.html.erb
index 05ed077f..6b4d7398 100644
--- a/app/views/blazer/queries/run.html.erb
+++ b/app/views/blazer/queries/run.html.erb
@@ -105,7 +105,7 @@
<% k = @columns[i] %>
<td>
<% if v.is_a?(Time) %>
- <% v = blazer_time_value(k, v) %>
+ <% v = blazer_time_value(@data_source, k, v) %>
<% end %>
<% unless v.nil? %>