繁体   English   中英

Ransack显示所有而不是过滤器

[英]Ransack showing all instead of filter

我试图使用Ransack gem,但它返回所有12,000行而不是使用过滤器。

控制器:

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

视图:

 <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> 

在seraching后,URL看起来没问题: URL

但它表现得像:

 @computers = LmiHost.all 

任何想法也为什么会发生这种情况?

你做错了是你没有指定一个合适的匹配器。 如果要选择特定的作业ID,则应在表单中指明搜索匹配器。

例如,你说job_id应该是job_id_eq或者你想要它的匹配器

你应该在哪里获得如下的Ransack搜索项目。

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

在你的Ransack搜索中我没有看到谓词因此它返回所有的resutls。

暂无
暂无

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

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