# Using render in observe\_field before

**URL:** <https://www.ruby-forum.com/t/using-render-in-observe-field-before/134400>\
**Category:** Deployment\
**Created:** [April 10, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/using-render-in-observe-field-before/134400 "2008-04-10T15:15:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rays](https://www.ruby-forum.com/u/rays)\
**Post date:** [April 10, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/using-render-in-observe-field-before/134400/1 "2008-04-10T15:15:01Z")

</div>

I want to use render(:partial =\> “loading”) in observe\_field’s before.  
For example:

# Can not run

\<%= observe\_field ‘username’,  
:on =\> ‘blur’,  
:update =\> ‘check\_username’,  
:url =\> {:action =\> ‘check\_username’},  
:before =\>  
“$(‘check\_username’).update(’#{render(:partial =\> “loading”)}’)”,  
:with =\> ‘username’ -%\>

# AJAX part, generate two lines

# Can run

\<%= text\_field\_tag ‘username’ %\>  
  
\<%= observe\_field ‘username’,  
:on =\> ‘blur’,  
:update =\> ‘check\_username’,  
:url =\> {:action =\> ‘check\_username’},  
:before =\> “$(‘check\_username’).update(’\<img  
src=”/images/loading.gif"\>Checking…’)",  
:with =\> ‘username’ -%\>

# AJAX part, generate only one line

# partial

\<%= img\_tag “/images/loading.gif” %\>Loading…

---

<div class="post-metadata">

**Author:** ![rays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rays](https://www.ruby-forum.com/u/rays)\
**Post date:** [April 18, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/using-render-in-observe-field-before/134400/2 "2008-04-18T17:02:29Z")

</div>

you might consider including the loading stuff in a hidden div, and  
then,  
when you trigger something with the observe field, you can use some  
javascript to show it. I think that this should work. Any other  
thoughts?

On Thu, Apr 10, 2008 at 9:15 PM, Ray Sun  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rays](https://www.ruby-forum.com/u/rays)\
**Post date:** [April 18, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/using-render-in-observe-field-before/134400/3 "2008-04-18T17:04:51Z")

</div>

Exactly what Scott said. Put it in a hidden div and show the div with  
ajax.

On Fri, Apr 18, 2008 at 11:01 AM, Scott Ballantyne  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > For example:
> > 
> > # AJAX part, generate only one line

–  
Greg N.  
Rails Developer & Designer  
Owner, [carbon8.us](http://carbon8.us)  
Blog, [20seven.org](http://20seven.org)

---

<div class="post-metadata">

**Author:** ![rays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rays](https://www.ruby-forum.com/u/rays)\
**Post date:** [April 18, 2008, 10:54pm UTC](https://www.ruby-forum.com/t/using-render-in-observe-field-before/134400/4 "2008-04-18T22:54:39Z")

</div>

Good point Scott, however, I’m assuming since he’s using observe\_field  
that  
he’s doing a round trip to process something.

On Fri, Apr 18, 2008 at 11:15 AM, Scott Ballantyne  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > ajax.
> > 
> > > On Thu, Apr 10, 2008 at 9:15 PM, Ray Sun \<
> > > 
> > > > ```
> > > > :url => {:action => 'check_username'},
> > > > :update => 'check_username',
> > > > 
> > > > ```
> > 
> > Owner, [carbon8.us](http://carbon8.us)  
> > Blog, [20seven.org](http://20seven.org)
> 
> >

–  
Greg N.  
Rails Developer & Designer  
Owner, [carbon8.us](http://carbon8.us)  
Blog, [20seven.org](http://20seven.org)

---

<div class="post-metadata">

**Author:** ![rays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rays](https://www.ruby-forum.com/u/rays)\
**Post date:** [April 18, 2008, 5:16pm UTC](https://www.ruby-forum.com/t/using-render-in-observe-field-before/134400/5 "2008-04-18T17:16:00Z")

</div>

I don’t think you need ajax, just javascript.  
if using prototype something like  
Element.show(‘loading’)  
this should work if you have a div with an id that’s loading.  
no need to make a round trip to the server.

On Fri, Apr 18, 2008 at 11:04 PM, Greg N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rays](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rays](https://www.ruby-forum.com/u/rays)\
**Post date:** [April 19, 2008, 6:23am UTC](https://www.ruby-forum.com/t/using-render-in-observe-field-before/134400/6 "2008-04-19T06:23:22Z")

</div>

Good point, but the value of the loading div is its immediacy in the  
user  
experience. So using javascript rather than ajax even if there is a  
trip to  
the server still has the advantage of being faster.

On Sat, Apr 19, 2008 at 4:54 AM, Greg N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
