# A question about ajax

**URL:** <https://www.ruby-forum.com/t/a-question-about-ajax/156588>\
**Category:** Rails\
**Created:** [December 30, 2008, 2:12pm UTC](https://www.ruby-forum.com/t/a-question-about-ajax/156588 "2008-12-30T14:12:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 30, 2008, 2:12pm UTC](https://www.ruby-forum.com/t/a-question-about-ajax/156588/1 "2008-12-30T14:12:09Z")

</div>

I defines a partial see below:  
\<%=  
puts @project.version  
text\_field\_tag “project\_version”, @project.version  
%\>

I want the project version update-to-date. The first line can print the  
correct version value but the text field doesn’t refresh to the new  
version.

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 30, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/a-question-about-ajax/156588/2 "2008-12-30T16:39:42Z")

</div>

Hi,

First of all, if you want to use puts in your views, use \<% %\> tags  
rather  
than \<%= %\> tags.  
Secondly, if you load your partials once you have your data  
object(@project)  
with appropriate value your page should display the same.  
But if you change the value of @project.version after the partial is  
loaded,  
it would not be reflected on the page until you reload the particular  
div  
which has the text field tag with the partial.

-NAYAK

On Tue, Dec 30, 2008 at 6:42 PM, Zhao Yi

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 30, 2008, 7:20pm UTC](https://www.ruby-forum.com/t/a-question-about-ajax/156588/3 "2008-12-30T19:20:45Z")

</div>

NAYAK wrote:

> First of all, if you want to use puts in your views, use \<% %\> tags  
> rather than \<%= %\> tags.

> ```
> I defines a partial see below:
> <%=
> puts @project.version
> text_field_tag "project_version", @project.version
> %>
> 
> ```

The above will puts the @project.version to the STDOUT stream, then will  
return  
the text\_field\_tag into the \<%= %\> location.

This is a subtle hair to split (and ‘p’ is more useful than ‘puts’  
there), but  
debugging out of the top of a \<%= %\>, while expressing its last line, is  
very  
common…

–  
Phlip

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 31, 2008, 3:30am UTC](https://www.ruby-forum.com/t/a-question-about-ajax/156588/4 "2008-12-31T03:30:57Z")

</div>

Vishwanath Nayak wrote:

> Hi,
> 
> First of all, if you want to use puts in your views, use \<% %\> tags  
> rather  
> than \<%= %\> tags.  
> Secondly, if you load your partials once you have your data  
> object(@project)  
> with appropriate value your page should display the same.  
> But if you change the value of @project.version after the partial is  
> loaded,  
> it would not be reflected on the page until you reload the particular  
> div  
> which has the text field tag with the partial.
> 
> -NAYAK
> 
> On Tue, Dec 30, 2008 at 6:42 PM, Zhao Yi

Hi,

This is my controller code:

def update\_project\_selection

@project = Project.find(:all,:conditions=\>"name=’#{selected\_project}’  
")  
render :partial =\> “project\_version”, :layout=\>false  
end

I update the @project object before load the partial. Why does the page  
display the same value?

Below is the view page:

\<%=  
select\_tag:project\_selection,options\_for\_select(@project\_names)  
%\>

\<%=  
observe\_field :project\_selection,  
:frequency =\> 0.5,  
:update =\> ‘ajaxWrapper’,  
:url =\> {:action =\> ‘update\_project\_selection’},  
:with =\> “‘project\_selection=’+encodeURIComponent(value)”  
%\>

---

<div class="post-metadata">

**Author:** ![youhaodeyi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/b9bd4f/32.png) [@youhaodeyi](https://www.ruby-forum.com/u/youhaodeyi)\
**Post date:** [December 31, 2008, 5:30am UTC](https://www.ruby-forum.com/t/a-question-about-ajax/156588/5 "2008-12-31T05:30:32Z")

</div>

I know what the problem. I set up a wrong update value in observe\_field  
element.
