Skip to content

Instantly share code, notes, and snippets.

@lucasmazza
Created April 17, 2010 02:26
Show Gist options
  • Select an option

  • Save lucasmazza/369198 to your computer and use it in GitHub Desktop.

Select an option

Save lucasmazza/369198 to your computer and use it in GitHub Desktop.
# Some fun with EnumerateIt
class LocationType < EnumerateIt::Base
associate_values(:House => 1, :Apartment => 2, :Island => 3)
end
class Location < ActiveRecord::Base
has_enumeration_for :location_type
LocationType.enumeration.values.each do |key, value|
scope value.to_s.downcase.pluralize, where(:location_type => key)
end
end
Location.houses
# [#<Location... ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment