chewmanfoo
2010-May-17 01:20 UTC
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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2010-May-17 16:32 UTC
Re: how to change one attribute (or a group of attributes) when another changes?
On May 16, 2010, at 6:20 PM, chewmanfoo wrote:> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-May-17 21:20 UTC
Re: how to change one attribute (or a group of attributes) when another changes?
On 17 May 2010 02:20, chewmanfoo <chewmanfoo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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?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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jason Michael
2010-May-17 21:29 UTC
Re: how to change one attribute (or a group of attributes) when another changes?
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 On Mon, May 17, 2010 at 4:20 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 17 May 2010 02:20, chewmanfoo <chewmanfoo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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? > > 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 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-May-17 23:31 UTC
Re: how to change one attribute (or a group of attributes)
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. > > JasonIf it''s a "rats nest", it will probably be faster to refactor than to try to maintain it as it is. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.