how to change one attribute (or a group of attributes) when another changes?

I have a hosts class with an ip_addresses class which has a host_id
attribute. All hosts are associated with a data_center, and all
ip_addresses are associated with a network. Networks have a standard
IP network definition (192.168.59.0/24) etc. When a user changes that
network definition, I need to go through all ip_addresses in the
network and change them to agree with the new network definition. For
example, if the network is defined as 192.168.59.0/24, and the user
changes it to 10.168.59.0/24 in the networks form, I need to change
all the ip_addresses in that network to match the new scheme. So I
need to know when the network changes. How do I do this? Like, is
there a way to add code to the function that sets the network
definition?

Add an 'after_save' method to your Network model that checks to see what's changed and if appropriate goes through and changes all of it's IP_Address children...

-philip

I think you have redundant data in the db, as you are storing the ip
address and the network definition, where much of the data is common
between these two. I suggest not storing the full ip address, just
the offset from that in the network definition, or something similar.
Then your problem will go away.

Colin

Colin,

You’re right! But I can’t go down that path right now. In the future I’ll refactor the heck out of tis rats nest, but for now I have to make it work.

Jason

Jason Michael wrote:

Colin,

You're right! But I can't go down that path right now. In the future
I'll
refactor the heck out of tis rats nest, but for now I have to make it
work.

Jason

If it's a "rats nest", it will probably be faster to refactor than to
try to maintain it as it is.

Best,