title: NoMethodError (undefined method `[]' for nil:NilClass): with jquery-datatables-rails
body: <p>I have been trying to get filtering working on jquery-datatables by following these <a href="http://www.enten-itc.ch/fr/posts/add-a-filter-form-to-a-ruby-on-rails-server-side-processing-datatable" rel="nofollow">instructions</a>.</p>
  
  <p>Before I added the filters it was returning the json needed by datatables without any issue but now I'm getting the above error and cannot identify the issue.</p>
  
  <pre><code>def index
      respond_to do |format|
        format.html
        format.json do
          @sbcons = Subcontractor.scoped
          filters = params[:filter]
          @sbcons = @sbcons.where(sbcon_type: filters[:type]) unless filters[:type].nil? or filters[:type].blank?
          @sbcons = @sbcons.where(cscs_card: filters[:cscs]) unless filters[:cscs].nil? or filters[:cscs].blank?
          @sbcons = @sbcons.where(approved_status: filters[:approved]) unless filters[:approved].nil? or filters[:approved].blank?
          render json: SubcontractorsDatatable.new(view_context, @sbcons)
        end
      end
    end
  
  &lt;% provide(:title, 'All Subcontractors') %&gt;
  &lt;h1&gt;Subcontractors List&lt;/h1&gt;
  &lt;div class="filter"&gt;
    &lt;%= form_tag(method: :get, id: "filter_form") do %&gt;
      &lt;%= label_tag :sbcon_type, "Type" %&gt;
      &lt;%= select_tag "filter[type]", options_for_select([[],["Labour Only"], ["Specialist"], ["Both"]]) %&gt;
      &lt;%= label_tag :cscs_card, "CSCS" %&gt;
      &lt;%= select_tag "filter[cscs]", options_for_select([[],["Yes"], ["No"]]) %&gt;
      &lt;%= label_tag :approved_status, "Approved Status" %&gt;
      &lt;%= select_tag "filter[status]", options_for_select([[],["Approved"], ["Not Approved"]]) %&gt; &lt;br&gt;
      &lt;%= link_to "Filter", '#', id: "filterbutton", class: "btn btn-mini" %&gt;
    &lt;% end %&gt;
    &lt;br&gt;
  &lt;/div&gt;
  &lt;table id="subcontractors" class="table table-condensed table-hover display" data-source="&lt;%= subcontractors_url(format: "json") %&gt;"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Name&lt;/th&gt;
        &lt;th&gt;Contact Number&lt;/th&gt;
        &lt;th&gt;CSCS&lt;/th&gt;
        &lt;th&gt;Type&lt;/th&gt;
        &lt;th&gt;Scotland&lt;/th&gt;
        &lt;th&gt;NE England&lt;/th&gt;
        &lt;th&gt;NW England&lt;/th&gt;
        &lt;th&gt;Midlands&lt;/th&gt;
        &lt;th&gt;SE England&lt;/th&gt;
        &lt;th&gt;SW England&lt;/th&gt;
        &lt;th&gt;London&lt;/th&gt;
        &lt;th&gt;Wales&lt;/th&gt;
        &lt;th&gt;Operatives&lt;/th&gt;
        &lt;th&gt;Product Liability&lt;/th&gt;
        &lt;th&gt;Employer Liability&lt;/th&gt;
        &lt;th&gt;Public Liability&lt;/th&gt;
        &lt;th&gt;Contractors All Risk&lt;/th&gt;
        &lt;th&gt;Status&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;%= javascript_tag do %&gt; 
    $('#filterbutton').click(function (){
      $('#subcontractors').dataTable().fnDraw();
    });
  &lt;% end %&gt;
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>NoMethodError (undefined method <code>[]' for nil:NilClass):
    app/controllers/subcontractors_controller.rb:31:in</code>block (2 levels) in index'
    app/controllers/subcontractors_controller.rb:26:in `index'</p>
  
  <p>Line 31: @sbcons = @sbcons.where(sbcon_type: filters[:type]) unless filters[:type].nil? or filters[:type].blank?</p>
  
  <p>Line 26: respond_to do |format|</p>