Class: Subregion
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Subregion
- Defined in:
- app/models/subregion.rb
Class Method Summary collapse
Class Method Details
.find_by_postcode(postcode) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/models/subregion.rb', line 4 def self.find_by_postcode(postcode) if postcode.strip.upcase =~ /^([A-Z][A-Z]?)/ prefix = '|' + $1 + '|' subregions = Subregion.arel_table Subregion.where(subregions[:postcode_prefix].matches("%#{prefix}%")).first else nil end end |