Reputation: 348
I am trying to use Ransack gem but it returns all 12,000 rows instead of using the filter.
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
But it is acting like :
@computers = LmiHost.all
Any ideas as too why this is happening?
Upvotes: 4
Views: 2120
Reputation: 2541
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.
for example you are saying job_id
where it should be job_id_eq
or what ever matcher you want it to be
where you should getter a Ransack Search item like following.
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.
Upvotes: 4