Sha256: 4cbb5c595b37af1ffd63ab711f05c38894d21305fe9958598d681e69311425d3
Contents?: true
Size: 1.67 KB
Versions: 11
Compression:
Stored size: 1.67 KB
Contents
class Dhatu::Testimonial < Dhatu::ApplicationRecord # Set Table Name self.table_name = "testimonials" # Including the State Machine Methods include Publishable include Featureable # Validations validates :name, presence: true, length: {minimum: 3, maximum: 256}, allow_blank: false validates :designation, presence: true, length: {minimum: 3, maximum: 256}, allow_blank: true validates :organisation, presence: true, length: {minimum: 3, maximum: 256}, allow_blank: true validates :statement, presence: true, allow_blank: false # Associations has_one :profile_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::ProfileImage" has_one :logo_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::LogoImage" # ------------------ # Class Methods # ------------------ scope :search, lambda {|query| where("LOWER(name) LIKE LOWER('%#{query}%') OR\ LOWER(designation) LIKE LOWER('%#{query}%') OR\ LOWER(organisation) LIKE LOWER('%#{query}%') OR\ LOWER(status) LIKE LOWER('%#{query}%')")} scope :upcoming, lambda { where("created_at >= ?", Time.now) } scope :past, lambda { where("created_at < ?", Time.now) } # ------------------ # Instance variables # ------------------ # Generic Methods # --------------- def to_param "#{id}-#{name.parameterize[0..32]}" end def display_name "#{name_was}" end # Permission Methods # ------------------ def can_be_edited? status?(:published) or status?(:unpublished) end def can_be_deleted? status?(:removed) end end
Version data entries
11 entries across 11 versions & 1 rubygems