Files
nairobi/app/models/progress_bar.rb
Julian Herrero 1ba50c76c4 Use method from Globalizable module
Since we have a method defined inside the Globalizable
module we don't need to create the same method in every model
2019-02-13 13:35:09 +01:00

24 lines
666 B
Ruby

class ProgressBar < ActiveRecord::Base
self.inheritance_column = nil
RANGE = 0..100
enum kind: %i[primary secondary]
belongs_to :progressable, polymorphic: true
translates :title, touch: true
include Globalizable
validates :progressable, presence: true
validates :kind, presence: true,
uniqueness: {
scope: [:progressable_type, :progressable_id],
conditions: -> { primary }
}
validates :percentage, presence: true, inclusion: RANGE, numericality: { only_integer: true }
before_validation :assign_model_to_translations
validates_translation :title, presence: true, unless: :primary?
end