Created
October 13, 2012 18:51
-
-
Save cheald/3885740 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Host < ActiveRecord::Base | |
validates_associated :access_points, :switches | |
before_validation :set_group_sizes | |
def set_group_sizes | |
associated = (self.access_points + self.switches).group_by(&:ip) | |
associated.each do |ip, o| | |
o.each do |obj| | |
obj.devices_on_ip = o.length | |
end | |
end | |
end | |
end | |
class Switch < ActiveRecord::Base | |
attr_accessor :devices_on_ip | |
validates :devices_on_ip, :numericality => {:less_than_or_equal_to => 1, :allow_blank => true} | |
end | |
class AccessPoint < ActiveRecord::Base | |
attr_accessor :devices_on_ip | |
validates :devices_on_ip, :numericality => {:less_than_or_equal_to => 1, :allow_blank => true} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment