Sha256: e147cce26250d87d1d48c22f5f5e08738129d974656916c2d6bcf2b71c3e2ced
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 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_invalid_phone?, message: I18n.t('activerecord.errors.messages.not_phone') validates_presence_of :description, minimum: 9, on: :update, if: lambda{|section| section.has_description == true } validates :description, numericality: { only_integer: true }, on: :update, if: :is_invalid_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: lambda{|section| section.key == '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'}}, # {'key' => {'name' => 'key'}}, ] end def self.icon "tasks" end def self.display_name 'Seccion' end def description if self.has_description return self.attributes['description'].html_safe else return self.attributes['description'] end end private def is_invalid_phone? key == 'phone' && description != '' end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
adminpanel-2.0.1 | app/models/adminpanel/section.rb |