Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 835 Bytes

README.rdoc

File metadata and controls

29 lines (20 loc) · 835 Bytes

Description

An ActiveRecord validation for determining if an Array is a subset of another Array.

Example

A real estate search that:

  • includes only houses and condos;

  • in suburbia or the west-end.

could be:

class RealEstateSearch < ActiveRecord::Base

  # params[:styles] => %w(House Condo)
  #   --> This would pass validation.
  validates_array_subset_of :styles,
    :in       => %w(House Apartment Condo),
    :message  => 'What kind of property are you looking for??'

  # params[:neighbourhoods] => %w(Suburbia Mars)
  #   --> This would fail validation, because "Mars" is not in the Array below.
  validates_array_subset_of :neighbourhoods,
    :in => %(Uptown Downtown Suburbia West-End East-End)

end

Copyright and License

Copyright © 2008 Nick Hoffman, released under the MIT license.