Last active
December 26, 2015 11:29
-
-
Save ArunGupta25/7144486 to your computer and use it in GitHub Desktop.
activerecord query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# params[:category] is an array of categories like ['tops, 'bottoms', 'outerwear']. | |
# For each category I have a corresponding array of sizes like ['M', 'L']. | |
# params[category] gives the sizes for the category. | |
#I want to return the given sizes in each category so I've created this loop. | |
# However I don't know how to merge the queries together. I think I'm supposed to use .merge but I'm not sure what to define @listings as so I can call .merge on it in the loop. | |
@listings = [] | |
params[:category].each do |category| | |
@listings += Listing.where(category: category, size: params[category], designer: params[:designer], sold: nil).include(:photos).page(params[:category_page]).per(@perpage) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"category"=>["tops", "bottoms", "outerwear", "raw denim", "suiting", "accessories", "footwear"], "designer"=>["3sixteen", "Alexander McQueen", "APC", "Band of Outsiders", "dfv", "dfvd", "dvf", "fglkbnf", "fgn", "J Crew", "lkndfv", "Naked and Famous", "RRL", "rtgrt", "Saturdays", "some designer", "tester", "Undercover", "Visvim", "wings and horns"], "tops"=>["31", "M"], "bottoms"=>["28x32", "32"], "outerwear"=>["L"], "rawdenim"=>["31", "34"], "footwear"=>["fgnhg"], "ajax"=>"1", "controller"=>"home", "action"=>"index"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment