Work around possible regression in rails

`pluck` used to always trigger a database query. With Rails 5.0.1 it uses data from
already loaded associations, this also includes new records for which we can not
generate agent_paths
This commit is contained in:
Dominik Sander 2016-12-27 23:35:29 +01:00
parent 0285a1a993
commit 070946e879

View file

@ -52,7 +52,7 @@
window.agentPaths = {};
window.agentNames = [];
<% if current_user.present? -%>
var myAgents = <%= Utils.jsonify(current_user.agents.pluck(:name, :id).inject({}) {|m, a| m[a.first] = agent_path(a.last); m }) %>;
var myAgents = <%= Utils.jsonify(current_user.agents.pluck(:name, :id).inject({}) {|m, a| next if a.last.nil?; m[a.first] = agent_path(a.last); m }) %>;
var myScenarios = <%= Utils.jsonify(current_user.scenarios.pluck(:name, :id).inject({}) {|m, s| m[s.first + " Scenario"] = scenario_path(s.last); m }) %>;
$.extend(window.agentPaths, myAgents);
$.extend(window.agentPaths, myScenarios);