I'm trying to add some code for my ActiveRecord class so that it is
executed whenever an object is updated, this code is a seperate
process that reads from the same table represented by my model class
so when it runs it needs the database to be up to date.
In the following situation this is fine:
# MyModel
def after_save
`/usr/local/bin/update_models -i #{self.id}`
end
# controller action delete
def delete
MyModel.find(params[:id]).update_attribute(:deleted_at, Time.now) #
after_save is called when the table
end
But in this situation:
# controller action new
def new
MyModel.transaction do
newmodel = MyModel.new
othermodel = MyOtherModel.new
... other code ...
newmodel.save!
othermodel.save!
end
end
after_save gets called inside the transaction, and so the database is
not up to date! I've looked into ActiveRecord::Observers but this also
faces the same problem. Is there any way around this?
# Here is my idea for how this might be achieved, given no knowledge
of how to accomplish it the rails way
# comments / feedback / criticism welcomed
# (note this is just a proof of concept not rails compatible code)