ruby on rails - reading multiple values from check box and display results in RoR -
i've 2 models brands , categories. display products comes under brands , categories.
after if check of brands nike, display proper result. later on if check nike , adidas under brands won't display nike products instead display adidas products.
here code.
def index catids=array.new brandids=array.new if(!(params[:catid].nil?) && params[:catid].to_s.downcase != "all") catids=arrayconvertion(params[:catid]) end if(!(params[:brandid].nil?) && params[:brandid].to_s.downcase != "all") brandids=arrayconvertion(params[:brandid]) end if(catids.length == 0 && brandids.length == 0) @products = product.order(:name).page(params[:page]).per(3) else if(catids.length == 0 && brandids.length != 0) in 0..(brandids.length - 1) @products[i]=product.where(:brands_test_id => brandids[i]).page(params[:page]).per(3) end else if(catids.length != 0 && brandids.length == 0) in 0..(catids.length - 1) @products[i]=product.where(:categories_test_id => catids[i]).page(params[:page]).per(3) end else in 0..(brandids.length - 1) j in 0..(catids.length - 1) @products=product.where(:brands_test_id => brandids[i]).where(:categories_test_id => catids[j]).page(params[:page]).per(3) end end end end end end def arrayconvertion(p1) arrid=array.new sv=p1.split(",") sv.each |s| if(s != "all") arrid << s.to_i end end return arrid end
here view part
<h1> product details </h1> <table> <% @products.each_slice(3) |p1|%> <tr> <% p1.each |p| %> <td> <div id="style"> <%= image_tag("images/#{p.id}.jpeg",:alt => p.name) %> <p> name: </p> <%= p.name %> <p> price: </p> <%= p.price %> <p> discount: </p> <%= p.discount %> </div> </td> <% end %> </tr> <% end %> </table> <div id="paginator"> <%= paginate @products,:remote => true %> </div>
i believe it's happening because of overwriting previous results instead of appending. please me fix this. believe
Comments
Post a Comment