Article:
  Ajax on Rails
Subject:   correct code
Date:   2006-04-19 03:05:46
From:   gvlx
Hi!


Checking for "observe_field" in http://api.rubyonrails.org/ gave me the answer.


If you use the following test code in the controller



def live_search
render_text "<p> "+ params.inspect + ".</p>"
end


I'll see the function 'observe_field' will not return the text unless told to do so (you were probably expected to retrive the field directly through the DOM).


change the rhtml to:



<label for="searchtext">Live Search:</label>
<%= text_field_tag :searchtext %>
<%= observe_field(:searchtext,
:frequency => 0.25,
:update => :search_hits,
:with => "searchtext",
:url => { :action => :live_search }) %>
<p>Search Results:</p>
<div id="search_hits"></div>


That will do it (until I learn to fetch the fields directly).


Best Regards
G.

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • correct code
    2006-04-19 03:09:48  gvlx [View]

    Humm.

    It actually returns the value as the key with a null value.

    What would I do with it?