From 93f5c213e0054ce555fd7ec21b6c90ee42d020d7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 20 Nov 2019 19:15:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=88=91=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/hack_user_lastest_code.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/hack_user_lastest_code.rb b/app/models/hack_user_lastest_code.rb index 1d3e20f87..28cc62db4 100644 --- a/app/models/hack_user_lastest_code.rb +++ b/app/models/hack_user_lastest_code.rb @@ -8,7 +8,7 @@ class HackUserLastestCode < ApplicationRecord belongs_to :user has_many :hack_user_codes, dependent: :destroy has_one :hack_user_debug - scope :mine, ->(author_id){ find_by(user_id: author_id) } + scope :mine, ->(author_id){ where(user_id: author_id) } scope :passed, -> {where(status: 1)} end From f149129f921e165a2f2ebf71f597b791a60d9b1e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 20 Nov 2019 19:21:06 +0800 Subject: [PATCH 2/3] 1 --- config/routes.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index abe31340d..81c419a7e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,7 +44,9 @@ Rails.application.routes.draw do get :start get :result end - resources :comments + resources :comments do + + end end resources :hack_user_lastest_codes, path: :myproblems, param: :identifier do From 7e50b42b9e55bb705ae506ea8041bf02a15966bf Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 20 Nov 2019 19:31:26 +0800 Subject: [PATCH 3/3] fixbug --- app/controllers/hacks_controller.rb | 2 +- app/models/hack_user_lastest_code.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index 213c38c7f..915e58882 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -27,7 +27,7 @@ class HacksController < ApplicationController # 筛选过滤与排序 params_filter_or_order # 我解决的编程题数 - user_codes = HackUserLastestCode.joins(:hack).mine(current_user).passed + user_codes = HackUserLastestCode.joins(:hack).mine_hack(current_user).passed @simple_count = user_codes.where(hacks: {difficult: 1}).count @medium_count = user_codes.where(hacks: {difficult: 2}).count @diff_count = user_codes.where(hacks: {difficult: 3}).count diff --git a/app/models/hack_user_lastest_code.rb b/app/models/hack_user_lastest_code.rb index 28cc62db4..b4a707603 100644 --- a/app/models/hack_user_lastest_code.rb +++ b/app/models/hack_user_lastest_code.rb @@ -8,7 +8,8 @@ class HackUserLastestCode < ApplicationRecord belongs_to :user has_many :hack_user_codes, dependent: :destroy has_one :hack_user_debug - scope :mine, ->(author_id){ where(user_id: author_id) } + scope :mine, ->(author_id){ find_by(user_id: author_id) } + scope :mine_hack, ->(author_id){ where(user_id: author_id) } scope :passed, -> {where(status: 1)} end