Skip to content

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

License

Notifications You must be signed in to change notification settings

nickhoffman/validates_array_subset_of-old

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published