Rails 3 和 MetaSearch
我正在尝试在我的应用程序中实现 meta_search gem 以过滤计费表中的各个字段:
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
和视图:
<%= 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 %>
当我单击选择其中一个过滤器时,出现错误:
无法找到没有 ID 的 Sla。
我假设这是因为我的 @sla.id 参数没有被传递到 @search,但我不知道我做错了什么。请帮助一个正在为此苦苦挣扎的可怜、劳累过度的女孩。 ;)
预先感谢您的任何建议。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这行
@sla = Sla.find(params[:sla_id])
应该看起来像
@search = Sla.serch(params[:search])
因为我假设您正在使用索引操作来显示 sla 之外的所有记录
,但显示您正在使用 params:id
@sla = Sla.find(params[:id])
可能是一个较晚的响应,但可能是有人会有同样的问题。
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.
我相信调用索引时缺少 :sla_id 参数。
I believe it is rather missing :sla_id parameter when index is called.