How build a advanced search with checkbox using Ransack?


how I build a advanced search how this image:

<a href="https://i.stack.imgur.com/yXELg.png" rel="nofollow"><img alt="advanced search with checkboxes" class="b-lazy" data-src="https://i.stack.imgur.com/yXELg.png" data-original="https://i.stack.imgur.com/yXELg.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

I have my controller, very basic yet:

def index @q = Product.ransack(params[:q]) @products = @q.result(distinct: true) end

And have my view:

<%= search_form_for @q do |f| %> <%= f.label :name_cont, "Name" %> <br /> <%= f.search_field :name_cont %> <br /> <%= f.label :brand, "Brand" %> <br /> <%= f.collection_check_boxes :brand, Product.all, :id, :brand %> <br /> <%= f.label :hd, "HD" %> <br /> <%= f.collection_check_boxes :hd, Product.all, :id, :hd %> <br /> <%= f.label :ram, "RAM" %> <br /> <%= f.collection_check_boxes :ram, Product.all, :id, :ram %> <br /> <%= f.submit "Search" %> <% end %>

But, the only thing that worked on search is the input name. And I have two problems. 1º The checkboxes don't worked. 2º Some checkboxes is repeting because I put Product.all, but too put distinct, but nothing worked =/ Can you help me please?


you can try following for brand, hd and ram

<% Product.pluck('distinct brand').each do |brand| %> <%= check_box_tag('q[brand_cont_any][]', brand ) %> <%= brand %> <% end %>


  • Ransack search error
  • Rails has_many :through association: save instance into join table
  • Objective-C – access extern const with a string containing its name? [duplicate]
  • Taking mean across rows grouped by a variable in numpy
  • Grouping by blank nodes
  • Single virtual attribute definition for multiple fields
  • Query to get the Top 2 from each group
  • Shopify API CARTS - Changing line_item line_price for price Override
  • How can I make a 100% stacked chart with nvd3?
  • How to implement limit with Nhibernate and Sybase
  • unrecognized selector with category NSMutableData
  • Returning the auto incrementing value after an insert using slick
  • xcode don't localize specific strings
  • Sending HTML Form Data to Spring REST Web Service
  • Swift: Switch statement fallthrough behavior
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • How to get next/previous record number?
  • Apache 2.4 - remove | delete | uninstall
  • php design question - will a Helper help here?
  • AngularJs get employee from factory
  • Proper way to use connect-multiparty with express.js?
  • Trying to get generic when generic is not available
  • Getting Messege Twice Using IMvxMessenger
  • embed rChart in Markdown
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • How to load view controller without button in storyboard?