Home > Software design >  How to add addition condition to ransack after submiiting the form
How to add addition condition to ransack after submiiting the form

Time:11-11

I have a book library rails app using ransack. Basically, after searching for book title and category. I want to have additional condition like in Amazon page. So I use link_to with parameter of ransack. But the problem is that the page will render the result will only base on the parameter which I sent in link_to. Is there a way that allow me to insert a condition in current search session of ransack. Thanks in advance.

CodePudding user response:

You'll need to merge the new condition into the existing filter and pass that hash to the path helper.

Something like this:

books_path(q: params[:q].merge(additional_filter_eq: value))
  • Related