Update first table when data is created in the second table

Hi,

I want to know how to update data in first table when i create data in
second table.

For ex:

1)locations-Fields(id,name,reply_data)-TABLE ONE

2)Events-Fields(id,name)-TABLE TWO

I want to know how to update the reply_data column in the first table
when
data is added to the Events table.

this should work with callbacks like after_create or after_save:

http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

just define them for table one and do whatever necessary with table two

Thorsten Mueller wrote:

this should work with callbacks like after_create or after_save:

http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

just define them for table one and do whatever necessary with table two

Can u show me an example as to how to do it..

in the model of table two:

after_create :update_reply_data

def update_reply_data
  @record = TableOne.find(...)
  @record.update_attribute(:reply_data, new_value)
end

for:
TableOne.find(...)
must have some useful findcode, of course
and:
new_value should be the new value for reply_data,
whatever that is, can't see that in your question

if the tables are related in some form, things get
more easy if you define this with belongs_to,
has_many and so on. but again i can't guess those
details from your question

Add an after_save filter.

http://api.rubyonrails.com/classes/ActiveRecord/Callbacks.html#M001298