Sha256: 7e05eceb866a7ab5b05ae6246f467b9d21f05575a23e78d809278b852e116c84

Contents?: true

Size: 609 Bytes

Versions: 3

Compression:

Stored size: 609 Bytes

Contents

class Press < ActiveRecord::Base

  set_table_name :press
  
  validates_presence_of :title
  validates :published_at, :datetime => true
  validates :url, :format => { :with => /(^(http|https):\/\/[a-z0-9]+([-.]{1}[a-z0-9]*)+. [a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix }, :unless => Proc.new{|record| record.url.blank? }
  
  has_many :images, :as => :viewable, :class_name => 'PressImage', :order => :position, :dependent => :destroy
  
  before_validation :fix_url
  
  private
  
    def fix_url
      return if url.blank?
      self.url = "http://#{url}" unless url =~ /^(http|https):\/\//i      
    end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_essential_press-0.2.0 app/models/press.rb
spree_essential_press-0.1.0.pre3 app/models/press.rb
spree_essential_press-0.1.0.pre2 app/models/press.rb