开发者

Rails 3 and MetaSearch

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}) %>
    <%=开发者_如何学Go 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜