Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scope :range_filter, lambda { |id, detail_min, detail_max|
- filter = Filter.find(id)
- detail_min = filter.minimum if detail_min.blank?
- detail_max = filter.maximum if detail_max.blank?
- puts detail_min
- puts detail_max
- joins(:filters).where(
- 'filters.id = ? AND CAST (offer_details.detail AS BIGINT) BETWEEN ? AND ?',
- id,
- detail_min,
- detail_max
- )
- }
- def show
- @category = Category.find(params[:id])
- @filters = @category.filters
- @offers = @category.offers
- @offer_details = @category.offer_details
- puts 'ПАРАМЕТРЫ'
- puts params
- puts @offers.class
- @filters.each do |filter|
- code_name = filter.code_name
- next unless params[code_name]
- if filter.type_filter == 'range'
- @offers = @offers.range_filter(filter.id, params[code_name][:min],
- params[code_name][:max])
- end
- end
- puts @offers.class
- @offers = @offers.paginate(page: params[:page], per_page: 10)
- end
- 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
- Processing by CategoriesController#show as HTML
- Parameters: {"win_percent"=>{"min"=>"", "max"=>""}, "game_count"=>{"min"=>"", "max"=>""}, "commit"=>"Поиск", "id"=>"16"}
- User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 14], ["LIMIT", 1]]
- Category Load (0.3ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
- CACHE Category Load (0.0ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT $2 [["id", 16], ["LIMIT", 1]]
- ↳ app/controllers/categories_controller.rb:5:in `show'
- ПАРАМЕТРЫ
- {"win_percent"=>{"min"=>"", "max"=>""}, "game_count"=>{"min"=>"", "max"=>""}, "commit"=>"Поиск", "controller"=>"categories", "action"=>"show", "id"=>"16"}
- Offer::ActiveRecord_Associations_CollectionProxy
- Filter Load (0.1ms) SELECT "filters".* FROM "filters" WHERE "filters"."category_id" = $1 [["category_id", 16]]
- ↳ app/controllers/categories_controller.rb:14:in `show'
- Filter Load (0.2ms) SELECT "filters".* FROM "filters" WHERE "filters"."id" = $1 LIMIT $2 [["id", 9], ["LIMIT", 1]]
- ↳ app/models/offer.rb:13:in `block in <class:Offer>'
- 0
- 100
- Filter Load (0.2ms) SELECT "filters".* FROM "filters" WHERE "filters"."id" = $1 LIMIT $2 [["id", 13], ["LIMIT", 1]]
- ↳ app/models/offer.rb:13:in `block in <class:Offer>'
- 0
- 100000
- Offer::ActiveRecord_AssociationRelation
- Rendering categories/show.html.erb within layouts/application
- Rendered filters/_range.html.erb (Duration: 0.1ms | Allocations: 102)
- Rendered filters/_range.html.erb (Duration: 0.0ms | Allocations: 101)
- 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]]
- ↳ app/views/categories/show.html.erb:20
- Rendered categories/show.html.erb within layouts/application (Duration: 4.4ms | Allocations: 3198)
- [Webpacker] Everything's up-to-date. Nothing to do
- Rendered layouts/_header.html.erb (Duration: 0.2ms | Allocations: 76)
- Completed 200 OK in 61ms (Views: 48.4ms | ActiveRecord: 3.0ms | Allocations: 27345)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement