# Ajax observe\_field not vorking on Rails

**URL:** <https://www.ruby-forum.com/t/ajax-observe-field-not-vorking-on-rails/195892>\
**Category:** Rails\
**Created:** [October 2, 2010, 3:23am UTC](https://www.ruby-forum.com/t/ajax-observe-field-not-vorking-on-rails/195892 "2010-10-02T03:23:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![site-master](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@site-master](https://www.ruby-forum.com/u/site-master)\
**Post date:** [October 2, 2010, 3:23am UTC](https://www.ruby-forum.com/t/ajax-observe-field-not-vorking-on-rails/195892/1 "2010-10-02T03:23:14Z")

</div>

down vote favorite

I am trying to create some kind of search in my ruby on rails  
application and I want to add ajax support. I want when a user types in  
a search box a word, ajax automatically generates the results. And I  
have searched almost all internet and I couldn’t find answer to  
following question:

When I type into my text area nothing happens. It is like ajax is not  
working at all. Tre problem is in observe\_field which should observe my  
id= ‘query’ but it seem like it not doing anything

I am using Prototype 1.6.1 and the newest version of rails. The code I  
wrote is:

viewer:

```
<form name="sform" action="" style="display:inline;">

```

Filter on Property No :   
\<%= text\_field\_tag(:query, params[‘query’], :size =\> 10, :id =\> ‘query’  
) %\>

\<%= image\_tag("/images/system/blue\_small.gif",  
:align =\> “absmiddle”,  
:border =\> 0,  
:id =\> “spinner”,  
:style =\>“display: none;” ) %\>

\<%= observe\_field ‘query’, :frequency =\> 1,  
:update =\> ‘table’,  
:before =\> “$(’#spinner’).show()”,  
:success =\> “$(’#spinner’).hide()”,  
:url =\> {:action =\> ‘list’},  
:with =\> ‘query’ %\>

\<%= render :partial =\> "items\_list" %\>

And my controler is:

def list

```
sort = case params['sort']
       when "Title" then "title"
       when "address" then "address"
       when "close date" then "close_date"
       when "property_no_reverse" then "property_no DESC"
       when "address_reverse" then "address DESC"
       when "close_date_reverse" then "close_date DESC"
       end

conditions = ["title LIKE ?", "%#{params[:query]}%"] unless

```

params[:query].nil?

```
@total = Message.count(:conditions => conditions)
 @accounts = Message.paginate :page => params[:page], :per_page =>

```

10, :order =\> sort, :conditions =\> conditions  
if request.xml\_http\_request?  
render :partial =\> “items\_list”, :layout =\> false  
end

end

I would greatly appreciate any help I can get!
