Sha256: c9e2270071f5e62653014061534af8c7239cef0826a79f2f5bafbe71ea2c493a

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

# Tableless model based on a forum post by Rick Olson
class SearchCriteria < ActiveRecord::Base
  #Search criteria does not need to be stored in the database so these two methods will spoof the column stuff
  def self.columns() @columns ||= []; end
  def self.column(name, sql_type = nil, default = nil, null = true)
    columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
  end
  
  column :start, :string
  column :stop, :string
  column :order_num, :string
  column :status, :integer
  column :customer, :string
  column :name, :string
  column :sku, :string
  
  def validate
    date_pattern = /^(0[1-9]|1[012])[\/][0-9]{2}[\/](19|20)[0-9]{2}$/
    errors.add(:start, "Must specify a start date") and return if start.blank? and not stop.blank?
    errors.add(:start, "Date must be formatted MM/DD/YYYY") unless start.blank? or date_pattern.match start.to_s
    errors.add(:stop, "Date must be formatted MM/DD/YYYY") unless stop.blank? or date_pattern.match stop.to_s
    unless stop.blank? 
      errors.add(:stop, "Stop date must be after start date") if DateTime.parse(stop) < DateTime.parse(start)  
    end
  end
  
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
railscart-0.0.1 starter-app/vendor/plugins/railscart/app/models/search_criteria.rb
railscart-0.0.2 starter_app/vendor/plugins/railscart/app/models/search_criteria.rb
railscart-0.0.4 starter_app/vendor/plugins/railscart/app/models/search_criteria.rb
railscart-0.0.3 starter_app/vendor/plugins/railscart/app/models/search_criteria.rb
spree-0.0.6 starter-app/vendor/plugins/spree/app/models/search_criteria.rb
spree-0.0.5 starter-app/vendor/plugins/spree/app/models/search_criteria.rb
spree-0.0.8 starter-app/vendor/plugins/spree/app/models/search_criteria.rb
spree-0.0.9 app/models/search_criteria.rb
spree-0.0.7 starter-app/vendor/plugins/spree/app/models/search_criteria.rb
spree-0.2.0 app/models/search_criteria.rb