# Ajax observe\_field not vorking on Rails

**URL:** <https://discuss.rubyonrails.org/t/ajax-observe-field-not-vorking-on-rails/54782>\
**Category:** rubyonrails-talk\
**Created:** [October 2, 2010, 1:23am UTC](https://discuss.rubyonrails.org/t/ajax-observe-field-not-vorking-on-rails/54782 "2010-10-02T01:23:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [October 2, 2010, 1:23am UTC](https://discuss.rubyonrails.org/t/ajax-observe-field-not-vorking-on-rails/54782/1 "2010-10-02T01: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:

&nbsp;&nbsp;&nbsp;&nbsp;\<form name="sform" action="" style="display:inline;"\> \<label for="item\_name"\>Filter on Property No : \</label\> \<%= text\_field\_tag(:query, params['query'], :size =\> 10, :id =\> 'query' ) %\> \</form\>

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

\<%= observe\_field 'query', :frequency =\> 1, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:update =\> 'table', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:before =\> "$('#spinner').show()", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:success =\> "$('#spinner').hide()", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\> {:action =\> 'list'}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:with =\> 'query' %\>

\<div id="table"\> \<%= render :partial =\> "items\_list" %\> \</div\>

And my controler is:

&nbsp;&nbsp;def list

&nbsp;&nbsp;&nbsp;&nbsp;sort = case params['sort'] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when "Title" then "title" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when "address" then "address" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when "close date" then "close\_date" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when "property\_no\_reverse" then "property\_no DESC" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when "address\_reverse" then "address DESC" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when "close\_date\_reverse" then "close\_date DESC" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;conditions = ["title LIKE ?", "%#{params[:query]}%"] unless params[:query].nil?

&nbsp;&nbsp;&nbsp;&nbsp;@total = Message.count(:conditions =\> conditions) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@accounts = Message.paginate :page =\> params[:page], :per\_page =\> 10, :order =\> sort, :conditions =\> conditions &nbsp;&nbsp;&nbsp;&nbsp;if request.xml\_http\_request? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :partial =\> "items\_list", :layout =\> false &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;end

I would greatly appreciate any help I can get!
