ajax - Implementing filters for search in my rails app -


i want create filters products in app not sure how that. on page products/ index display collection of products created form :

  = form_tag products_path, method: 'get', :remote => true, class: 'form-inline min-marged-top' ||               .form-group                 = check_box_tag :price                 = check_box_tag :weight                 = button_tag(type: 'submit', value: "go", class: 'btn btn-success') 

the idea when user ticks checkbox price or weight, products reordered price / weight. ajax form , why use :remote => true. first, noticed using checkbox_tag, value of checkboxes don't change when tick them or not : stay equal 1. shouldn't changing when checkbox ticked or not ? assuming value should equal 1 when checkbox clicked wanted in product_controller in method index (knowing can have params[:content] sent through search form) :

 def index     if params[:content].present? && (params[:price] == "1")       @products = product.search(params[:content]).order(price: :desc).paginate(:page => params[:page], :per_page => 2)       respond_to |format|         format.js {}         format.html{ render :index }       end     elsif params[:content].present? && (params[:weight] == "1")       @products = product.search(params[:content]).order(weight: :desc).paginate(:page => params[:page], :per_page => 2)       respond_to |format|         format.js {}         format.html{ render :index }     elsif params[:price] == "1"       @products = product.all.order(price: :desc).paginate(:page => params[:page], :per_page => 2)       respond_to |format|         format.js {}         format.html{ render :index }     elsif params[:weight] == "1"       @products = product.all.order(weight: :desc).paginate(:page => params[:page], :per_page => 2)       respond_to |format|         format.js {}         format.html{ render :index }     else       @products = product.all.paginate(:page => params[:page], :per_page => 2)     end   end 

is way implement filter price & weight products in app ?


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -