scinote-web/app/models/result_text.rb

33 lines
968 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-06-23 21:19:08 +08:00
class ResultText < ApplicationRecord
2019-03-11 20:43:50 +08:00
include TinyMceImages
2023-08-11 20:48:20 +08:00
include ActionView::Helpers::TextHelper
2019-03-20 21:40:18 +08:00
2023-09-04 19:58:11 +08:00
auto_strip_attributes :name, nullify: false
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
auto_strip_attributes :text, nullify: false
validates :text, length: { maximum: Constants::RICH_TEXT_MAX_LENGTH }
belongs_to :result, inverse_of: :result_texts, touch: true
has_one :result_orderable_element, as: :orderable, dependent: :destroy
2023-08-11 20:48:20 +08:00
def duplicate(result, position = nil)
ActiveRecord::Base.transaction do
new_result_text = result.result_texts.create!(
text: text
)
# Copy results tinyMce assets
clone_tinymce_assets(new_result_text, result.my_module.team)
result.result_orderable_elements.create!(
position: position || result.result_orderable_elements.length,
orderable: new_result_text
)
new_result_text
end
end
2016-02-12 23:52:43 +08:00
end