1

I am trying to implement the meta_search gem in my application to filter on various fields in a billing table:

  class PeriodBillingsController < ApplicationController
    def index
      @sla = Sla.find(params[:sla_id])
      @search = PeriodBilling.latest_billing.search(params[:search])
      @period_billings = @search.order("we_date desc").where("sla_id = ?", @sla.id)
    end
  end

And the view:

  <%= form_for @search do |f| %>
    <%= f.label :pe_number_eq, "Period #" %>
    <%= select("period_billing", "pe_number", (1..12), {:include_blank => true}) %>
    <%= f.label :appcode_eq, "Appcode" %>
    <%= collection_select( "period_billing", "appcode_id", Appcode.where("sla_id = ?", @sla.id), :id, :appcode, :include_blank => true ) %>
    <%= f.label :dpc_employee_eq, "Named Resource" %>
    <%= collection_select( "period_billing", "dpc_employee_id", DpcEmployee.all, :id, :fullname, :include_blank => true ) %>
  <%= f.submit "Filter Records" %>
  <% end %>

When I click to select one of the filters, I get an error:

Couldn't find an Sla without an ID.

I'm assuming it's because my @sla.id param isn't being carried to the @search, but I don't know what I'm doing wrong. Please help a poor, overworked girl who is struggling with this. ;)

Thanks in advance for any advice.

Katie M
  • 1,111
  • 6
  • 21
  • 31

2 Answers2

0

I believe it is rather missing :sla_id parameter when index is called.

m4risU
  • 1,231
  • 11
  • 14
0

this line

@sla = Sla.find(params[:sla_id])

should've looked like

@search = Sla.serch(params[:search])

cause I assume you are using index action to display all records off sla

but in show you are using with params:id

@sla = Sla.find(params[:id])

probably it's a late response but may be someone will have the same issue.

rmagnum2002
  • 11,341
  • 8
  • 49
  • 86