Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. scope :range_filter, lambda { |id, detail_min, detail_max|
  2. filter = Filter.find(id)
  3. detail_min = filter.minimum if detail_min.blank?
  4. detail_max = filter.maximum if detail_max.blank?
  5. puts detail_min
  6. puts detail_max
  7.  
  8. joins(:filters).where(
  9. 'filters.id = ? AND CAST (offer_details.detail AS BIGINT) BETWEEN ? AND ?',
  10. id,
  11. detail_min,
  12. detail_max
  13. )
  14. }
  15.  
  16.  
  17.  
  18. def show
  19. @category = Category.find(params[:id])
  20. @filters = @category.filters
  21. @offers = @category.offers
  22. @offer_details = @category.offer_details
  23.  
  24. puts 'ПАРАМЕТРЫ'
  25. puts params
  26. puts @offers.class
  27.  
  28. @filters.each do |filter|
  29. code_name = filter.code_name
  30. next unless params[code_name]
  31.  
  32. if filter.type_filter == 'range'
  33. @offers = @offers.range_filter(filter.id, params[code_name][:min],
  34. params[code_name][:max])
  35. end
  36. end
  37. puts @offers.class
  38. @offers = @offers.paginate(page: params[:page], per_page: 10)
  39. end
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. Started GET "/categories/16?win_percent%5Bmin%5D=&win_percent%5Bmax%5D=&game_count%5Bmin%5D=&game_count%5Bmax%5D=&commit=%D0%9F%D0%BE%D0%B8%D1%81%D0%BA" for 127.0.0.1 at 2020-03-29 19:31:58 +0700
  47. Processing by CategoriesController#show as HTML
  48. Parameters: {"win_percent"=>{"min"=>"", "max"=>""}, "game_count"=>{"min"=>"", "max"=>""}, "commit"=>"Поиск", "id"=>"16"}
  49. User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 14], ["LIMIT", 1]]
  50. Category Load (0.3ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
  51. CACHE Category Load (0.0ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
  52. ↳ app/controllers/categories_controller.rb:5:in `show'
  53. ПАРАМЕТРЫ
  54. {"win_percent"=>{"min"=>"", "max"=>""}, "game_count"=>{"min"=>"", "max"=>""}, "commit"=>"Поиск", "controller"=>"categories", "action"=>"show", "id"=>"16"}
  55. Offer::ActiveRecord_Associations_CollectionProxy
  56. Filter Load (0.1ms) SELECT "filters".* FROM "filters" WHERE "filters"."category_id" = $1 [["category_id", 16]]
  57. ↳ app/controllers/categories_controller.rb:14:in `show'
  58. Filter Load (0.2ms) SELECT "filters".* FROM "filters" WHERE "filters"."id" = $1 LIMIT $2 [["id", 9], ["LIMIT", 1]]
  59. ↳ app/models/offer.rb:13:in `block in <class:Offer>'
  60. 0
  61. 100
  62. Filter Load (0.2ms) SELECT "filters".* FROM "filters" WHERE "filters"."id" = $1 LIMIT $2 [["id", 13], ["LIMIT", 1]]
  63. ↳ app/models/offer.rb:13:in `block in <class:Offer>'
  64. 0
  65. 100000
  66. Offer::ActiveRecord_AssociationRelation
  67. Rendering categories/show.html.erb within layouts/application
  68. Rendered filters/_range.html.erb (Duration: 0.1ms | Allocations: 102)
  69. Rendered filters/_range.html.erb (Duration: 0.0ms | Allocations: 101)
  70. Offer Load (2.0ms) SELECT "offers".* FROM "offers" INNER JOIN "offer_details" ON "offer_details"."offer_id" = "offers"."id" INNER JOIN "filters" ON "filters"."id" = "offer_details"."filter_id" WHERE "offers"."category_id" = $1 AND (filters.id = 9 AND CAST (offer_details.detail AS BIGINT) BETWEEN 0 AND 100) AND (filters.id = 13 AND CAST (offer_details.detail AS BIGINT) BETWEEN 0 AND 100000) LIMIT $2 OFFSET $3 [["category_id", 16], ["LIMIT", 10], ["OFFSET", 0]]
  71. ↳ app/views/categories/show.html.erb:20
  72. Rendered categories/show.html.erb within layouts/application (Duration: 4.4ms | Allocations: 3198)
  73. [Webpacker] Everything's up-to-date. Nothing to do
  74. Rendered layouts/_header.html.erb (Duration: 0.2ms | Allocations: 76)
  75. Completed 200 OK in 61ms (Views: 48.4ms | ActiveRecord: 3.0ms | Allocations: 27345)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement