Sha256: 38c7648825730b9ac21a4660daf4fcb50ac4584dbe4bbe7d392df18fa39ef8c3
Contents?: true
Size: 1.84 KB
Versions: 7
Compression:
Stored size: 1.84 KB
Contents
require 'carrierwave' require 'carrierwave/orm/activerecord' module Adminpanel class Section < ActiveRecord::Base include Adminpanel::Base mount_images :images validates_length_of :description, minimum: 10, maximum: 10, on: :update, if: :is_a_phone?, message: I18n.t('activerecord.errors.messages.not_phone') validates_presence_of :description, minimum: 9, on: :update, if: :has_description validates :description, numericality: { only_integer: true }, on: :update, if: :is_a_phone? validates_presence_of :key validates_presence_of :name validates_presence_of :page VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates_format_of :description, with: VALID_EMAIL_REGEX, if: :is_email? default_scope { order("page ASC") } scope :of_page, lambda{ |page| where(page: page) } scope :with_description, -> { where.not( description: '') } def self.form_attributes [ {'description' => {'name' => 'Descripcion', 'description' => 'label', 'label' => 'Seccion'}}, {'name' => {'name' => 'name', 'label' => 'Seccion'}}, {'key' => {'name' => 'key', 'label' => 'Llave'}}, {'page' => {'name' => 'page'}}, ] end def self.icon 'tasks' end def self.display_name 'Seccion' end def description if self.has_description && !self.attributes['description'].nil? return self.attributes['description'].html_safe else return self.attributes['description'] end end protected def has_description? !self.has_description.nil? || self.has_description end def is_email? key == 'email' && description != '' end def is_a_phone? key == 'phone' && description != '' end end end
Version data entries
7 entries across 7 versions & 1 rubygems