Sha256: a2948ad05c0231172fd6dc1221555852f43ab6b9bda095b8d44229222eecb5c5
Contents?: true
Size: 890 Bytes
Versions: 10
Compression:
Stored size: 890 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
10 entries across 10 versions & 2 rubygems