I am using advanced search in Ransack which has default AND. I have made it as OR by putting .try(:merge, m: 'or'))
@search = Data.search(params[:q].try(:merge, m: 'or'))
but I am not able to get the AND/OR drop down as Condition Group like shown in Ransack Demo here http://ransack-demo.herokuapp.com/users/advanced_search
How to do it as unfortunately Ransack wiki has no mention about it.
OUR CODE
data_controller.rb
def search
@search = Data.search(params[:q])
@datum = @search.result(:distinct=>true).paginate(page: params[:page], per_page: 10)
if params[:q].nil?
@datum = Prospect.where(:id => 0).paginate(page: params[:page], per_page: 10)
end
@page = params[:page] || 0
@pids = @search.result(:distinct=>true).pluck(:id)
@search.build_condition
# @search.build_grouping unless @search.groupings.any? (I have tried this code too but this gives an error)
end
routes.rb
resources :data do
collection do
get :search
post :search, to: 'data#search'
end
end
data.html.erb
<script type="text/javascript">
var ids = <%= @pids %>;
</script>
<section class="psf">
<div class="container">
<h1>All Data</h1>
<div class="row">
<div class="col-lg-10">
<div class="form_search">
<%= search_form_for @search, url: search_data_index_path, html: { method: :get, class: "data_search" } do |f| %>
<%= f.condition_fields do |c| %>
<%= render "condition_fields", f: c %>
<% end %>
<p><%= link_to_add_fields "Add Conditions", f, :condition %></p>
<br>
<div class="actions">
<%= f.submit "Search", :class => "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
</div>
<br>
<% if [email protected]? %>
<div class="total_count"><b><%= @pids.count %> Records Found.</b></div>
<% end %>