I have been working on developing a dynamic reporting feature as part of a larger project. The specific issue I am facing is that the functionality works fine for multiple calls but eventually leads to a server crash. I am utilizing mongoid and puma server - please feel free to ask if you need more details.
Despite extensive research, I have hit a wall with this problem. Any help would be greatly appreciated!
Error Message in Console The error message displayed here is just the beginning, with additional details provided in subsequent pages such as "Control frame information", "Other runtime information", and the "Process memory map"
/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/forwardable.rb:228: [BUG] Segmentation fault at 0x00000000000038
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
Important JavaScript Code Segment This script stores the category field value and adds all selected column values (from a multiselect form) to an array. Subsequently, both variables are sent to the get_filter_columns controller action.
<script>
$(document).ready(function(){
function get_filter_columns(filter_columns, category){
$.get('reports/get_filter_columns',{filter_columns, category});
};
$(document).on('change', "#filter_columns", function() {
var filter_column_array = [];
var category = $("#report_category").val();
$("#filter_columns .box2 option").each(function() {
filter_column_array.push($(this).val());
});
get_filter_columns(filter_column_array, category);
});
});
</script>
_filter_columns.html.erb This code snippet represents an element in the view that responds to the onchange event in JavaScript.
<div id = "filter_columns" class="col-lg-5">
<div class = "ibox-content report_builder_body">
<h2>Filter Columns</h2>
<%= simple_fields_for :filter_columns_nested_form do |ff| %>
<%= ff.select( :filter_columns, (@category || Account).attribute_names.map{ |value| [value.to_s.underscore.humanize, value] }, {}, { :id => "filter_columns", :class => "form-control dual_select_filter_columns", :multiple => true }) %>
<% end %>
</div>
</div>
reports_controller.rb This is the controller action invoked by the JavaScript code.
def get_filter_columns
@category = (params[:category] || "Account").split(' ').collect(&:capitalize).join.constantize
@filter_categories = (params[:filter_columns] || []).map{ |filter| filter }
@filter_symbols = {}
@filter_logic = ["Equal to", "Not equal to", "Less than", "Less than or equal to", "Greater than", "Greater than or equal to", "Is between", "Is not between"]
@filter_categories.each do |fs|
if @category.instance_methods(false).include?(fs.to_s.to_sym) == true
@filter_symbols[fs] = "enum"
elsif @category.pluck(fs.to_s.to_sym)[0].class.to_s == "BSON::ObjectId"
@filter_symbols[fs] = "string"
elsif @category.pluck(fs.to_s.to_sym)[0].class.to_s == "NilClass"
@filter_symbols[fs] = "string"
elsif @category.pluck(fs.to_s.to_sym)[0].class.to_s == "Time"
@filter_symbols[fs] = "date"
else
@filter_symbols[fs] = @category.pluck(fs.to_s.to_sym)[0].class.to_s || "string"
end
end
render "reports/js_templates/get_filter_columns.js.erb"
end
get_filter_columns.js.erb This file contains the JavaScript template that is rendered by the get_filter_columns controller action.
$('#filters').replaceWith('<%= j render("reports/partials/filters") %>');
_filters.html.erb This partial is being rendered by the get_filter_columns.js.erb file.
<div class="col-lg-7" id = "filters">
<div class = "ibox-content report_builder_body">
<h2>Filter Criteria</h2>
<div class="scroll_content">
<% if @filter_categories.nil? || @filter_categories.size == 0 %>
<p> No filter columns have been selected! </p>
<% else %>
<%= simple_fields_for :filters_nested_form do |ff| %>
<% (@filter_categories || []).each do |filter| %>
<div class = "col-lg-3">
<h5>
<%= filter.to_s.underscore.humanize %>:
</h5>
</div>
<%= ff.simple_fields_for :"#{filter}" do |fff| %>
<div class = "col-lg-5">
<%= fff.input :logic, collection: @filter_logic, label: false %>
</div>
<div class = "col-lg-4">
<%= fff.input :criteria, as: :"#{@filter_symbols[filter].to_s.downcase}", label: false %>
</div>
<% end %>
<% end %>
<% end %>
<% end %>
</div>
</div>
</div>