The source code shows as follows
app/views/admin/content/_form.rhtml
<%= text_field_tag(:search) %><br>
<div id=search_indicator_div
style="postition: absolute; left: your_X px; top: your_Y px">
<%= image_tag("/images/spinner.gif", :id =>
''indicator_gif_id'',
:style => ''display:none'') %>
</div>
<%= observe_field(:search,
:frequency => 0.5,
:update => :results,
:url => { :action => :search },
:loading => "Element.show(''indicator_gif_id'')",
:complete =>
"Element.hide(''indicator_gif_id'')") %>
<span id="results"></span>
app/controllers/admin/content_controller.rb
def search
@q = request.raw_post
# optionally handle the query however you''d like
# fetch some results from a database
@results = Tlc.find(:all, :conditions => [ "loc LIKE ?",
"%" + @q
+"%"])
end
whereas Tlc is a table that I created and loc is one column in this
table.
app/views/admin/content/search.rhtml
<% if @results.length > 0 && @q != ''''-%>
<table border=1 cellpadding=3px cellspacing=0px>
<tr>
<td align=center>
<b>Location</b>
</td>
<td align=center>
<b>State</b>
</td>
</tr>
<% for result in @results %>
<tr>
<td align=center>
<%= result.loc -%><br>
</td>
<td>
<%= result.st -%>
</td>
</tr>
</table>
<% end %>
<% else -%>
<% if @q != '''' -%>
Sorry, there are no results for:
<br> <b><%=h @q -%>
<% end -%>
<% end -%>
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---