Skip to content

Commit

Permalink
Better pattern for variables - existing code is safe, but could be er…
Browse files Browse the repository at this point in the history
…ror-prone in future
  • Loading branch information
ankane committed Jun 5, 2019
1 parent 9b91c36 commit 1fee713
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/helpers/pg_hero/home_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ def pghero_pretty_ident(table, schema: nil)
@database.quote_ident(ident)
end
end

def pghero_js_var(name, value)
"var #{name} = #{json_escape(value.to_json(root: false))};".html_safe
end
end
end
12 changes: 6 additions & 6 deletions app/views/pg_hero/home/_query_stats_slider.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
</div>

<script>
var sort = <%= @sort.to_json.html_safe %>;
var minAverageTime = <%= @min_average_time.to_json %>;
var minCalls = <%= @min_calls.to_json %>;
var debug = <%= @debug.to_json %>;
var startAt = <%= params[:start_at] ? @start_at.to_i * 1000 : "null" %>;
var endAt = <%= @end_at.to_i %> * 1000;
<%= pghero_js_var("sort", @sort) %>
<%= pghero_js_var("minAverageTime", @min_average_time) %>
<%= pghero_js_var("minCalls", @min_calls) %>
<%= pghero_js_var("debug", @debug) %>
<%= pghero_js_var("startAt", params[:start_at] ? @start_at.to_i * 1000 : nil) %>
<%= pghero_js_var("endAt", @end_at.to_i * 1000) %>

initSlider();
</script>

0 comments on commit 1fee713

Please sign in to comment.