diff --git a/app/controllers/hack_user_lastest_codes_controller.rb b/app/controllers/hack_user_lastest_codes_controller.rb index 814d16d51..08ca3ff77 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_codes + @records_count = records.count + @records = paginate records.created_order + end diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index d2dcbe145..f93b2dab5 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 - @hack.destroy - base_attrs = { - user_id: user_id, viewed: 0, tiding_type: 'System', trigger_user_id: current_user.id, - parent_container_type: "HackDelete" - } - @hack.tidings.create!(base_attrs) - 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", extra: "#{@hack.name}" + } + @hack.tidings.create!(base_attrs) + @hack.destroy + render_ok + rescue => e + logger.error("####hack_delete_error: #{e.message}") + render_error("删除失败") + end + end private 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 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 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