Rails filter with button or link_to using Ransack

前端 未结 2 762
灰色年华
灰色年华 2021-01-16 12:18

I am developing a rails application using the Ransack gem and below is the code that I have written so far to filter my database which works like a charm. Now what I am tryi

2条回答
  •  借酒劲吻你
    2021-01-16 12:33

    Replace

    <%= link_to "All",q: {color_cont: 'white'}, :class => 'link-sort', :remote => true, :method => :post %>

    with

    <%= link_to "All",q: {color_cont: 'white', brand_id_eq: params[:q][:brand_id_eq]}, :class => 'link-sort', :remote => true, :method => :post %>

    Here assumption is

    Once the database is first filtered with a brand name, then I would like users to be able to further filter the database by clicking one of the buttons which has a pre-defined filter value

提交回复
热议问题