From 3528f3764eb36cb3a256447e0a00258ae2f148d3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 25 Dec 2019 13:48:06 +0800 Subject: [PATCH 1/5] 1 --- app/controllers/hacks_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index d2dcbe145..9faa28ea3 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -131,12 +131,12 @@ class HacksController < ApplicationController def new;end def destroy - @hack.destroy base_attrs = { - user_id: user_id, viewed: 0, tiding_type: 'System', trigger_user_id: current_user.id, + user_id: @hack.user_id, viewed: 0, tiding_type: 'System', trigger_user_id: current_user.id, parent_container_type: "HackDelete" } @hack.tidings.create!(base_attrs) + @hack.destroy render_ok end From d7efe742a7c2d3db5e9396b399f32cf82b3b3b32 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 25 Dec 2019 13:57:18 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hacks_controller.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index 9faa28ea3..df9bab36a 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -131,13 +131,19 @@ class HacksController < ApplicationController def new;end def destroy - base_attrs = { - user_id: @hack.user_id, viewed: 0, tiding_type: 'System', trigger_user_id: current_user.id, - parent_container_type: "HackDelete" - } - @hack.tidings.create!(base_attrs) - @hack.destroy - render_ok + begin + base_attrs = { + user_id: @hack.user_id, viewed: 0, tiding_type: 'System', trigger_user_id: current_user.id, + parent_container_type: "HackDelete" + } + @hack.tidings.create!(base_attrs) + @hack.destroy + render_ok + rescue => e + logger.error("####hack_delete_error: #{e.message}") + render_error("删除失败") + end + end private From ed2445b6acb3266be315655dbf5c3ccab310186e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 25 Dec 2019 14:05:19 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hack_user_lastest_codes_controller.rb | 5 ++++- .../submit_records.json.jbuilder | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/hack_user_lastest_codes_controller.rb b/app/controllers/hack_user_lastest_codes_controller.rb index 814d16d51..afa58290c 100644 --- a/app/controllers/hack_user_lastest_codes_controller.rb +++ b/app/controllers/hack_user_lastest_codes_controller.rb @@ -61,7 +61,10 @@ class HackUserLastestCodesController < ApplicationController # 提交记录 def submit_records - @records = @my_hack.hack_user_codes.created_order + records = @my_hack.hack_user_code + @records_count = records.count + @records = paginate records.created_order + end diff --git a/app/views/hack_user_lastest_codes/submit_records.json.jbuilder b/app/views/hack_user_lastest_codes/submit_records.json.jbuilder index 797bda742..a73d58c4e 100644 --- a/app/views/hack_user_lastest_codes/submit_records.json.jbuilder +++ b/app/views/hack_user_lastest_codes/submit_records.json.jbuilder @@ -1,4 +1,8 @@ -json.array! @records do |hack_user| - json.(hack_user, :id, :created_at, :status, :execute_time, :execute_memory) - json.language hack_user.hack.language -end \ No newline at end of file +json.records do + json.array! @records do |hack_user| + json.(hack_user, :id, :created_at, :status, :execute_time, :execute_memory) + json.language hack_user.hack.language + end +end + +json.records_count @records_count \ No newline at end of file From 726a981b33b6289deb5f473c4b8350f8024ce63e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 25 Dec 2019 14:13:12 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hack_user_lastest_codes_controller.rb | 2 +- app/controllers/hacks_controller.rb | 2 +- app/decorators/tiding_decorator.rb | 2 +- app/models/hack.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/hack_user_lastest_codes_controller.rb b/app/controllers/hack_user_lastest_codes_controller.rb index afa58290c..08ca3ff77 100644 --- a/app/controllers/hack_user_lastest_codes_controller.rb +++ b/app/controllers/hack_user_lastest_codes_controller.rb @@ -61,7 +61,7 @@ class HackUserLastestCodesController < ApplicationController # 提交记录 def submit_records - records = @my_hack.hack_user_code + records = @my_hack.hack_user_codes @records_count = records.count @records = paginate records.created_order diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index df9bab36a..f93b2dab5 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -134,7 +134,7 @@ class HacksController < ApplicationController begin base_attrs = { user_id: @hack.user_id, viewed: 0, tiding_type: 'System', trigger_user_id: current_user.id, - parent_container_type: "HackDelete" + parent_container_type: "HackDelete", extra: "#{@hack.name}" } @hack.tidings.create!(base_attrs) @hack.destroy diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb index a9f60b890..8e0c402dd 100644 --- a/app/decorators/tiding_decorator.rb +++ b/app/decorators/tiding_decorator.rb @@ -412,6 +412,6 @@ module TidingDecorator end def hack_content - I18n.t(locale_format(parent_container_type)) % container&.name + I18n.t(locale_format(parent_container_type)) % (container&.name || extra) end end diff --git a/app/models/hack.rb b/app/models/hack.rb index b94eddbd2..37e1f239d 100644 --- a/app/models/hack.rb +++ b/app/models/hack.rb @@ -14,7 +14,7 @@ class Hack < ApplicationRecord # 点赞 has_many :praise_treads, as: :praise_tread_object, dependent: :destroy # 消息 - has_many :tidings, as: :container, dependent: :destroy + has_many :tidings, as: :container belongs_to :user From 97cb40d2ee4f853a3e5fe7af1754987b06f565d9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 25 Dec 2019 14:25:17 +0800 Subject: [PATCH 5/5] =?UTF-8?q?Fork=E5=8E=9F=E5=9B=A0=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/shixun_info.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/shixun_info.rb b/app/models/shixun_info.rb index 321b4c44a..7f7aa364e 100644 --- a/app/models/shixun_info.rb +++ b/app/models/shixun_info.rb @@ -1,6 +1,7 @@ class ShixunInfo < ApplicationRecord belongs_to :shixun validates_uniqueness_of :shixun_id + validates_length_of :fork_reason, maximum: 60 after_commit :create_diff_record private