Sha256: 668c017abbbd9d216bc21585fe34805a5ae857454eb82db477be8adef2984226

Contents?: true

Size: 839 Bytes

Versions: 3

Compression:

Stored size: 839 Bytes

Contents

class TbCommerce::Customization < ActiveRecord::Base
  self.table_name = 'tb_commerce_customizations'

  serialize :options, Array

  validates :title, :presence => true
  validates :input_type, :inclusion => {:in => ['text', 'list', 'select', 'textarea'], :message => 'must be either plain text or list selection'}
  validates :field_type, :inclusion => {:in => ['text', 'number', 'tel','email'], :message => ''}
  validate :has_at_least_one_option

  has_many :product_customizations, :inverse_of => :customization, :dependent => :destroy, :foreign_key => :tb_commerce_customization_id
  has_many :products, :through => :product_customizations

private

  def has_at_least_one_option
    if input_type == 'list' && (options.blank? || options.length == 0)
      errors.add(:options, 'must contain at least one option')
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_commerce-0.0.4 app/models/tb_commerce/customization.rb
tb_commerce-0.0.3 app/models/tb_commerce/customization.rb
tb_commerce-0.0.2 app/models/tb_commerce/customization.rb