このコミットが含まれているのは:
2026-03-12 21:41:28 +09:00
コミット 60c8c63353
7個のファイルの変更35行の追加17行の削除
+1 -1
ファイルの表示
@@ -90,7 +90,7 @@ class WikiPagesController < ApplicationController
return head :unprocessable_entity if name.blank? || body.blank?
tag_name = TagName.find_or_create_by!(name:)
tag_name = TagName.find_undiscard_or_create_by!(name:)
page = WikiPage.new(tag_name:, created_user: current_user, updated_user: current_user)
if page.save
message = params[:message].presence
+20
ファイルの表示
@@ -0,0 +1,20 @@
module MyDiscard
extend ActiveSupport::Concern
included { include Discard::Model }
class_methods do
def find_undiscard_or_create_by! attrs, &block
record = with_discarded.find_by(attrs)
if record&.discarded?
record.undiscard!
record.update_columns(created_at: record.reload.updated_at)
end
record or create!(attrs, &block)
rescue ActiveRecord::RecordNotUnique
retry
end
end
end
+3 -3
ファイルの表示
@@ -1,5 +1,5 @@
class Tag < ApplicationRecord
include Discard::Model
include MyDiscard
class NicoTagNormalisationError < ArgumentError
;
@@ -134,10 +134,10 @@ class Tag < ApplicationRecord
end
def self.find_or_create_by_tag_name! name, category:
tn = TagName.find_or_create_by!(name: name.to_s.strip)
tn = TagName.find_undiscard_or_create_by!(name: name.to_s.strip)
tn = tn.canonical if tn.canonical_id?
Tag.find_or_create_by!(tag_name_id: tn.id) do |t|
Tag.find_undiscard_or_create_by!(tag_name_id: tn.id) do |t|
t.category = category
end
rescue ActiveRecord::RecordNotUnique
+2 -6
ファイルの表示
@@ -1,5 +1,5 @@
class TagName < ApplicationRecord
include Discard::Model
include MyDiscard
default_scope -> { kept }
@@ -27,10 +27,6 @@ class TagName < ApplicationRecord
private
def sanitise_name
self.name = TagNameSanitisationRule.sanitise(name)
end
def canonical_must_be_canonical
if canonical&.canonical_id?
errors.add :canonical, 'canonical は実体を示す必要があります.'
@@ -50,7 +46,7 @@ class TagName < ApplicationRecord
end
def name_must_be_sanitised
if name != TagNameSanitisationRule.sanitise(name)
if name? && name != TagNameSanitisationRule.sanitise(name)
errors.add :name, '名前に使用できない文字が含まれてゐます.'
end
end
+1 -1
ファイルの表示
@@ -2,7 +2,7 @@ require 'set'
class WikiPage < ApplicationRecord
include Discard::Model
include MyDiscard
default_scope -> { kept }