简体   繁体   English

Ransack显示所有而不是过滤器

[英]Ransack showing all instead of filter

I am trying to use Ransack gem but it returns all 12,000 rows instead of using the filter. 我试图使用Ransack gem,但它返回所有12,000行而不是使用过滤器。

Controller: 控制器:

  def list @q = LmiHost.ransack(params[:q]) if !(params[:commit].nil?) then @computers = @q.result else @computers = LmiHost.where(:job_id => 121) end end 

View: 视图:

 <script type="text/javascript"> $(document).ready(function() { $("#computer_search_results").dataTable(); }); </script> <table id="computer_search_table"> <%= search_form_for @q do |f| %> <tr><td>Project:</td><td><%= f.select :job_id, @project_job_selector %></td></tr> <tr><td><%= f.submit 'Search' %></td></tr> <%end%> </table> <table id="computer_search_results"> <thead> <tr> <th>Lmi Name</th> <th>Service Tag</th> <th>Model</th> <th>Ship Date</th> <th>Warranty Date</th> <th>Project</th> <th>Invoice Name</th> </tr> </thead> <tbody> <% @computers.each do |computer| %> <tr> <td><%= computer.host_description %></td> <td><%= computer.host_service_tag %></td> <td><%= computer.host_model %></td> <td><%= computer.ship_date %></td> <td><%= computer.warranty_date %></td> <td><%= computer.job.name unless computer.job.nil? %></td> <td><%= computer.invoice_name %></td> </tr> <% end %> </tbody> </table> 

the URL looks okay after seraching: URL 在seraching后,URL看起来没问题: URL

But it is acting like : 但它表现得像:

 @computers = LmiHost.all 

Any ideas as too why this is happening? 任何想法也为什么会发生这种情况?

What you are doing wrong is that you are not specifying a proper matcher. 你做错了是你没有指定一个合适的匹配器。 if you want to select particular job id you should indicate the search matcher in the form. 如果要选择特定的作业ID,则应在表单中指明搜索匹配器。

for example you are saying job_id where it should be job_id_eq or what ever matcher you want it to be 例如,你说job_id应该是job_id_eq或者你想要它的匹配器

where you should getter a Ransack Search item like following. 你应该在哪里获得如下的Ransack搜索项目。

Ransack::Search<class: LmiHost, base: Grouping <conditions: [Condition <attributes: ["job_id"], predicate: eq, values: ["123"]>], combinator: and>> 

in your Ransack search I don't see the predicate hence it returns all the resutls. 在你的Ransack搜索中我没有看到谓词因此它返回所有的resutls。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM