Sha256: c5503d7c5d6ea9f148e2845def2543c9b58248698f5dc5f3a28ed8772b4d3f96
Contents?: true
Size: 843 Bytes
Versions: 16
Compression:
Stored size: 843 Bytes
Contents
module Gaku class GradingMethodSetItem < ActiveRecord::Base belongs_to :grading_method belongs_to :grading_method_set validates :grading_method_set_id, :grading_method_id, presence: true validates :grading_method_id, uniqueness: { scope: :grading_method_set_id, message: I18n.t(:'grading_method_set_item.already') } before_create :proper_position after_destroy :refresh_positions private def proper_position return unless grading_method_set self.position = grading_method_set.grading_method_set_items.count end def refresh_positions items = grading_method_set.grading_method_set_items items.pluck(:id).each_with_index do |id, index| items.update_all(position: index, id: id) end end end end
Version data entries
16 entries across 16 versions & 2 rubygems