I have created search forms using Ransack, but I have a problem. When I leave input empty I would like form not to send these inputs, so it won’t appear in my parameters.
Right now when i leave filters empty
They anyway apear in my url params and I am affraid that when I add many more filters it would cause problems
http://localhost:3000/records?q%5Btitle_cont%5D=&commit=Search
How could I get rid of that? I understand that I am passing ''
in that input.
controller:
class RecordsController < ApplicationController
def index
@q = Record.ransack(params[:q])
@records = @q.result(distinct: true)
end
form:
<%= search_form_for @q do |f| %>
<%= f.label :title_cont %>
<%= f.search_field :title_cont %>
<%= f.submit %>
<% end %>