# Auto refresh field

**URL:** <https://www.ruby-forum.com/t/auto-refresh-field/149384>\
**Category:** Rails\
**Created:** [September 24, 2008, 11:11am UTC](https://www.ruby-forum.com/t/auto-refresh-field/149384 "2008-09-24T11:11:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex2101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@Alex2101](https://www.ruby-forum.com/u/Alex2101)\
**Post date:** [September 24, 2008, 11:11am UTC](https://www.ruby-forum.com/t/auto-refresh-field/149384/1 "2008-09-24T11:11:23Z")

</div>

Hi,

I would to know if it is possible to automaticly refresh some  
particular field ?  
Clearly, I have a model called “productions” with fileds “name” and  
“numbers”.  
Another application update fields “numbers” of the mysql table.  
On an “index.html.erb”, I have the list of “production” and i would  
like to view automaticly when value of “numbers” change.

First of all, is it possible ?  
Because I may have many records, and in a close futur, more fields to  
monitor, I would like to update just choosen filed and not the whole  
page.

Thanks in advance.

PS : I just begun with ror…

---

<div class="post-metadata">

**Author:** ![Alex2101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@Alex2101](https://www.ruby-forum.com/u/Alex2101)\
**Post date:** [September 24, 2008, 2:44pm UTC](https://www.ruby-forum.com/t/auto-refresh-field/149384/2 "2008-09-24T14:44:07Z")

</div>

Hello,

Look at the prototype helper : periodically\_call\_remote  
It will call an action each X second. In this action, you should have  
a render like :

render :update do |page|  
page[‘my\_field\_id’].replace\_html “

updated!

”  
end

---

<div class="post-metadata">

**Author:** ![Alex2101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@Alex2101](https://www.ruby-forum.com/u/Alex2101)\
**Post date:** [September 24, 2008, 2:51pm UTC](https://www.ruby-forum.com/t/auto-refresh-field/149384/3 "2008-09-24T14:51:46Z")

</div>

Ok, i do understand the idea, but i don’t know where to apply it…

2008/9/24 joserwan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > like to view automaticly when value of “numbers” change.

–  
Cordialement,  
Alexandre P.

---

<div class="post-metadata">

**Author:** ![Alex2101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@Alex2101](https://www.ruby-forum.com/u/Alex2101)\
**Post date:** [September 25, 2008, 10:17am UTC](https://www.ruby-forum.com/t/auto-refresh-field/149384/4 "2008-09-25T10:17:16Z")

</div>

I finally find how to do :  
In the controler I create a method :  
def update\_nbpiece  
@production = Production.find(params[:id])  
render :text=\>@production.numbers  
end

Then in the index.html.erb, inside the for loop :  
\<%= periodically\_call\_remote(:update =\> “nbpiece\_id\_” +  
production.id.to\_s,  
:url =\> {:action =\> “update\_nbpiece”, :id=\>production.id}, :frequency =\>  
1  
)%\>  
…

\<%=h production.numbers%\> ...

Now the strange thinks, is that when use the Aptana’s internal browser,  
it  
works, but when I run another web browser, like IE or Firefox, I got the  
following error :  
\*PeriodicalExecuter is not  
defined[http://www.google.com/url?q=http://www.answers.com/defined&r=67&sa=X&oi=dict&ct=D&cd=1&usg=AFQjCNFuvFJmznBKueoiUXuoQSNCuy0xBA](http://www.google.com/url?q=http://www.answers.com/defined&r=67&sa=X&oi=dict&ct=D&cd=1&usg=AFQjCNFuvFJmznBKueoiUXuoQSNCuy0xBA)  
rails[http://www.google.com/url?q=http://www.answers.com/rails&r=67&sa=X&oi=dict&ct=D&cd=2&usg=AFQjCNHlo-0vsLWU3qaE-1UK1xKYlQhRtg](http://www.google.com/url?q=http://www.answers.com/rails&r=67&sa=X&oi=dict&ct=D&cd=2&usg=AFQjCNHlo-0vsLWU3qaE-1UK1xKYlQhRtg)  
\*  
Any ideas ??

2008/9/24 Alexandre P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > > Clearly, I have a model called “productions” with fileds “name” and  
> > > Thanks in advance.
> > > 
> > > PS : I just begun with ror…
> > > 
> > > >
> 
> –  
> Cordialement,  
> Alexandre P.

–  
Cordialement,  
Alexandre P.

---

<div class="post-metadata">

**Author:** ![Alex2101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@Alex2101](https://www.ruby-forum.com/u/Alex2101)\
**Post date:** [September 25, 2008, 2:50pm UTC](https://www.ruby-forum.com/t/auto-refresh-field/149384/5 "2008-09-25T14:50:00Z")

</div>

Maybe Aptana automatically include links to prototype as it misses.  
You have to include in your page header :

\<%= javascript\_include\_tag :all %\>

or less (don’t know wich file is needed for the updater) :

\<%= javascript\_include\_tag ‘prototype’ %\>

Erwan

On Sep 25, 4:16 am, “Alexandre P.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Alex2101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3da27b/32.png) [@Alex2101](https://www.ruby-forum.com/u/Alex2101)\
**Post date:** [September 25, 2008, 3:11pm UTC](https://www.ruby-forum.com/t/auto-refresh-field/149384/6 "2008-09-25T15:11:47Z")

</div>

that’s it!

Thanks !

2008/9/25 joserwan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Erwan
> 
> > Then in the index.html.erb, inside the for loop :  
> > it  
> > 2008/9/24 Alexandre P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> > 
> > > > It will call an action each X second. In this action, you should have
> > > > 
> > > > > particular field ?  
> > > > > page.  
> > > > > Cordialement,  
> > > > > Alexandre P.

–  
Cordialement,  
Alexandre P.
