# How to ensure

**URL:** <https://www.ruby-forum.com/t/how-to-ensure/165658>\
**Category:** Rails\
**Created:** [April 16, 2009, 5:04am UTC](https://www.ruby-forum.com/t/how-to-ensure/165658 "2009-04-16T05:04:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [April 16, 2009, 5:04am UTC](https://www.ruby-forum.com/t/how-to-ensure/165658/1 "2009-04-16T05:04:00Z")

</div>

how do i get my app database info only after another server has  
called my app’s method and  
updated my app’s database? Now, i can just get the database info  
before anther server calls my app’s method.

def one  
some code  
two  
some code  
end

def two  
calls another server’s methods and sends my app ping url(http://  
myhost/…/three) that will be automaticlly called by that server  
after executing the two method  
end

def three  
another server calls this method and updates database  
end

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [April 16, 2009, 8:12am UTC](https://www.ruby-forum.com/t/how-to-ensure/165658/2 "2009-04-16T08:12:50Z")

</div>

I need your help!Thanks!

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [April 16, 2009, 12:01pm UTC](https://www.ruby-forum.com/t/how-to-ensure/165658/3 "2009-04-16T12:01:11Z")

</div>

It seems i have not show the question very clear.  
While my app codes is accessing the db,anohter server is updating the  
db.  
so What i want is not accessing the db until the db is updated.I think  
there must be a ruby or rails method to do it, but can not find it.  
Thanks!

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [April 16, 2009, 1:32pm UTC](https://www.ruby-forum.com/t/how-to-ensure/165658/4 "2009-04-16T13:32:06Z")

</div>

hi,any one help me?

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [April 16, 2009, 2:23pm UTC](https://www.ruby-forum.com/t/how-to-ensure/165658/5 "2009-04-16T14:23:17Z")

</div>

2009/4/16 daociyiyou [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > > end
> > 
> > > > def three  
> > > > another server calls this method and updates database  
> > > > end

Because of the way Rails is usually deployed, this will be very  
difficult.  
When Rails is first called and the code starts to execute, it is in  
instance #1  
It then runs through the code and calls a method that invokes the  
remote service.  
(now you want it to wait)  
When the remote service calls back, because instance #1 is busy, it  
will invoke the method on instance #2 which has no knowledge of  
instance #1 or it’s waiting.

Two quick ways I can think of to solve this.

1. Don’t let the remote service update the database, get it to return  
the data and you update the database within the same method call so  
you’re always in control
2. If that’s not possible, return from the method and use AJAX or a  
page refresh to check if the remote service has done what it should  
and display the results after that.

Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)  
[http://www.linkedin.com/in/andrewtimberlake](http://www.linkedin.com/in/andrewtimberlake)

“I have never let my schooling interfere with my education” - Mark Twain

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [April 16, 2009, 6:39pm UTC](https://www.ruby-forum.com/t/how-to-ensure/165658/6 "2009-04-16T18:39:07Z")

</div>

thanks.It seems i can not use active record callback.

On 4ÔÂ16ÈÕ, ÏÂÎç8Ê±22·Ö, Andrew T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
