Search for a reversal by several criteria (checkbox) when checking

Shows an error in my code, I am using Ransak search, but I am not getting the search results output. I want to get the result when I check the size parameter from a checkbox. if i click medium i want to display all medium dresses like all please give me a solution

this is my checkbox

enter image description here

here is my code

product / index.html.slim

= search_form_for @product_search, url: shop_index_path do |f| = f.label :size_cont, "Size Available" - StandardSize.all.each do |s| = check_box_tag('product_search[standard_sizes_id_eq_any_cont][]', s.id ) = s.name

here is my ShopController.rb

class ShopController < ApplicationController def index @product_search = Product.ransack(params[:q]) @products = @product_search.result(distinct:true).page(params[:page]).per(8) @product_search.build_sort if @product_search.sorts.empty? end

model standards.rb

class StandardSize < ActiveRecord::Base belongs_to :product end

here is my model product.rb

class Product < ActiveRecord::Base has_and_belongs_to_many :standard_sizes end

this is my server getting Started GET "/shop?utf8=%E2%9C%93&q%5Bname_cont%5D=dress&q%5Bprice_paisas_gteq%5D=&q%5Bprice_paisas_lteq%5D=&product_search%5Bstandard_sizes_id_eq_all%5D%5B%5D=3&commit=Search" for 10.0.2.2 at 2015-07-23 10:12:42 +0000 Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by ShopController#index as HTML Parameters: {"utf8"=>"✓", "q"=>{"name_cont"=>"dress", "price_paisas_gteq"=>"", "price_paisas_lteq"=>""}, "product_search"=>{"standard_sizes_id_eq_all"=>["3"]}, "commit"=>"Search"} User Load (0.1ms) SELECT

users .* FROM

users WHERE

users .

id = 1 ORDER BY

users .

idASC LIMIT 1

+3


source to share


1 answer


Unless you have configured Ransack otherwise, all search options should be nested under @q

. I also had success _in

instead _eq_any_cont

.

Replace

= search_form_for @product_search, url: shop_index_path do |f|
  = f.label :size_cont, "Size Available"
  - StandardSize.all.each do |s|
    = check_box_tag('product_search[standard_sizes_id_eq_any_cont][]', s.id ) 
    = s.name

      



from

= search_form_for @q, url: shop_index_path do |f|
  = f.label :size_cont, "Size Available"
  - StandardSize.all.each do |s|
    = f.check_box :standard_sizes_id_in, {multiple: true}, s.id, nil
    = s.name

      

+4


source







All Articles