按参数过滤在开发中有效,但在生产中无效

Filtering by params works in development but not in production

我有一个跟踪调度呼叫的 Rails 3.2.22 应用程序,每个呼叫都属于一个区域,并且一个区域有很多呼叫。在我看来,我最初收到了来自所有区域的所有呼叫,但现在我在视图中使用简单的 form_tag 按区域过滤,并将区域 ID 作为参数传递给控制器​​并返回视图。

所以在本地,如果我点击调用索引视图,我将触发一个 url,例如:

http://loopify.xyz:9001/calls?utf8=%E2%9C%93&region=1

这将在我的视图中显示区域 ID 为“1”的所有呼叫。我可以切换到视图中的不同区域,它会按区域显示正确过滤的呼叫。

当我将它部署到我的登台服务器时,参数过滤根本不起作用并显示所有调用,即使当我 select 一个区域时我会得到一个 URL 像:

http://staging.example.com/calls?utf8=%E2%9C%93&region=1

这是我的调用控制器的索引操作:

  def index
   if params[:region].present?
     @region = params[:region]
     @assigned = Call.includes(:units, :transferred_from, :transferred_to, :nature, :region, :service_level).where(region_id: params[:region]).assigned_calls.until_end_of_day
     @unassigned = Call.includes(:units, :transferred_from, :transferred_to, :nature, :region, :service_level).where(region_id: params[:region]).unassigned_calls.until_end_of_day
   else
     params[:region] = "1"
     @assigned = Call.includes(:units, :transferred_from, :transferred_to, :nature, :region, :service_level).where(region_id: params[:region]).assigned_calls.until_end_of_day
     @unassigned = Call.includes(:units, :transferred_from, :transferred_to, :nature, :region, :service_level).where(region_id: params[:region]).unassigned_calls.until_end_of_day
   end
    @note = Note.new
    @units = Unit.active.order("unit_name").map{|unit| unit.calls.where(call_status: "open").empty? ? ["#{unit.unit_name} #{unit.unit_type.unit_type} #{unit.status.unit_status}", unit.id] : ["#{unit.unit_name} (on call) #{unit.unit_type.unit_type} #{unit.status.unit_status}", unit.id] }
  end

这是我的 index.html.erb 观点:

<div id="active">
  <%= render "assigned_calls" %>
</div>

<div id="inactive">
  <%= render "unassigned_calls" %>
</div>


<script>
  $(function() {
    setInterval(function(){
      $.getScript('/calls/?region=<%= params[:region] %>')
    }, 20000);
  });
</script>

这是 index.js.erb 文件以允许 ajax 刷新和 JS

$("#active").html("<%= escape_javascript render("assigned_calls") %>");
$("#inactive").html("<%= escape_javascript render("unassigned_calls") %>");

这是指定部分的摘录。已分配和未分配的都非常大,可以完整显示在这里,但如果您需要更多上下文,我们很乐意在 github 要点中提供它们。

<div class="page-header well">
  <h3><%= pluralize(@assigned.size, "Active Call") %></h3>
</div>
<%= form_tag calls_path, :method => 'get' do %>
  <%= select_tag "region", options_from_collection_for_select(Region.order(:area), :id, :area, selected: @region), prompt: "Choose Region" %>
  <%= submit_tag "Select", :name => nil, :class => 'btn' %>
<% end %>
<% @assigned.each_with_index do |call, index| %>
  <div class="widget">
    <div class="widget-header">
      <div class="pull-right">

        <%= link_to 'View', call, :class => 'btn btn-primary btn-small'%>
        <% if dispatch? || admin? || manager? || operations? %>
        <%= link_to 'Edit', edit_call_path(call), :class => 'btn btn-info btn-small'%>
        <%= link_to "Close", '#close-modal', data: {toggle: "modal", target: "#close-modal#{index}" }, class: 'btn btn-small btn-warning' %>
        <%= render 'layouts/close_call_modal', call: call, index: index %>
        <%= link_to "Cancel", '#cancel-modal', data: {toggle: "modal", target: "#cancel-modal#{index}" }, class: 'btn btn-small btn-danger' %>
        <%= render 'layouts/cancel_call_modal', call: call, index: index %>
        <%= link_to "Notes", '#note-modal', data: {toggle: "modal", target: "#note-modal#{index}" }, class: 'btn btn-small btn-primary' %>
        <%= render 'layouts/note_modal', call: call, index: index %>
        <% end %>
      </div>
      <i class="icon-phone"></i>
      <h3><%= link_to call.incident_number, call %> <span><%= status(call) %></span></h3>
      <% if call.wait_return == "yes" && call.parent_call_id == nil %>
        <i class="icon-arrow-right dim"></i> <span class="badge badge-important" >Initial Transport</span>
      <% end %>
      <% if call.wait_return == "yes" && call.parent_call_id.present? %>
        <i class="icon-arrow-left dim"></i> <span class="badge badge-important" >Return Transport</span>
      <% end %>
      <% if call.traffic_type == "Emergency" %>
      <span class="badge badge-important"><%= call.traffic_type %></span>
      <% else %>
      <span class="badge badge-info"><%= call.traffic_type %></span>
     <% end %>
     <span class="badge badge-primary" ><%= call.region.try(:area) %></span>
     <span class="badge badge-info" ><%= call.service_level.try(:level_of_service) %></span>
    </div>
 <% end %>

我真的不确定这里有什么问题。在开发中,我使用 Thin 为应用程序提供服务,在暂存阶段,我使用 passenger 和 nginx。

我的代码中是否缺少某些在生产环境中无法运行的内容?

回顾一下,区域过滤在开发中工作得很好,但一旦部署到暂存中,过滤就不起作用了。

我深入研究了日志,这是来自开发(本地)和生产(暂存)日志的请求:

开发人员:

Started GET "/calls/?region=1&_=1468278029235" for 127.0.0.1 at 2016-07-11 18:00:29 -0500
Processing by CallsController#index as JS

产品:

Started GET "/calls/?region=1&_=1468278074295" for 192.168.130.1 at 2016-07-11 18:01:14 -0500
Processing by CallsController#index as JS

我不确定为什么会这样 happens/works 但确实如此。如果我将 production.rb 中的日志级别从信息转为调试,参数过滤工作正常。我在旧的 github 问题上看到了对此的引用。 Rails 核心将其作为非错误关闭,但显然这是有原因的。不幸的是,3.2 不再受支持,因此 "hack" 将不得不这样做。现在是时候将应用程序升级到 4.2.6 了。