No luck. I''m still having the same problem. It works fine, but
everything
outside the div is being duplicated when the search results are loaded. You
end up with three or four search boxes on the page.
Here''s the updated page:
search.rhtml:
<html>
<head>
<title>All Books</title>
</head>
<body>
<%= define_javascript_functions %>
<form action="search">
<input id="search" name="search" type="text"
value="<% @params[''search'']
%>">
<input type="submit" name="Search">
</form>
<%= observe_field ''search'', :frequency => 0.5,
:update => ''search_results'', :url =>
{ :controller => ''book'', :action=>
''search'' },
:with => "''search='' + escape(value)" %>
<%= render_partial ''search_results'' %>
</body>
</html>
_search_results.rhtml:
<div id="search_results">
<% if @params[''search''] %>
<table border="1">
<tr>
<td><p align="center"><i><b><a
href="?sort=author,%20title">Author</a></b></i></td>
<td><p
align="center"><i><b>Titles</b></i></td>
<td><p align="center"><i><b><a
href="?sort=id">Stock Num.</a></b></i></td>
</tr>
<% @books.each do |book| %>
<tr>
<td><%= book.author %></td>
<td><%= book.title %></td>
<td><%= link_to book.id, :action => "edit", :id =>
book.id %></td>
</tr>
<% end %>
</table>
<% else %>
No query specified or no matches
<% end %>
</div>
book_controller.rb excerpt:
def search
require_dependency "search"
if @params[''search'']
@books = Book.search @params[''search''], :only =>
["books.author"], :case =>
:sensitive
render_without_layout
else
end
end
On 5/6/05, Jason Foreman
<threeve.org-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Break your search_results div out into a partial, and then use
>
> in search.rhtml:
> [...] # put this in place of the <div
id="search_results">...
> <%= render_partial ''search_results'' %>
> [...]
>
> in _search_results.rhtml:
> <div id="search_results">
> [...] # all the stuff you took out of search.rhtml
> </div>
>
> in book_controller.rb:
>
> book_controller (excerpt):
> def search
> require_dependency "search"
> if @params[''search'']
> @books = Book.search @params[''search''], :only =>
> ["books.author"], :case => :sensitive
> render_partial ''search_results''
> else
> end
> end
>
> This will have the effect of only rendering the search results div if
> you have the parameter search in the request, which you can then
> inject into the page. I''ve not tested this so you might have to
tweak
> it, but it should get you close.
>
> HTH,
>
> Jason
>
> On 5/6/05, Mike Payson
<mikepayson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Ok, I''ve -almost- got it working. Everything works fine, but
instead
> > of replacing the div with the search result, it''s replaces it
with the
> > entire page. The result is that the search box (and anything else
> > above or below the div) is duplicated. How do I specify the html code
> > to use for the div?
> >
> > Thanks!
> >
> > (And I really am beginning to grasp this stuff-- just barely, but
I''m
> > getting there!)
> >
> > Here''s the code I''m using (using the search routines
from
> > http://wiki.rubyonrails.com/rails/show/TextSearch):
> >
> > book_controller (excerpt):
> > def search
> > require_dependency "search"
> > if @params[''search'']
> > @books = Book.search @params[''search''], :only =>
> > ["books.author"], :case => :sensitive
> > render_without_layout
> > else
> > end
> > end
> >
> > search.rhtml
> > <html>
> > <head>
> > <title>All Books</title>
> > </head>
> > <body>
> > <%= define_javascript_functions %>
> >
> > <form action="search">
> > <input id="search" name="search"
type="text" value="<% @params[''search'']
> %>">
> > <input type="submit" name="Search">
> > </form>
> >
> > <%= observe_field ''search'', :frequency => 0.5,
> > :update => ''search_results'', :url =>
> > { :controller => ''book'', :action=>
''search'' },
> > :with => "''search='' + escape(value)"
%>
> >
> > <div id="search_results">
> > <% if @params[''search''] %>
> > <table border="1">
> > <tr>
> > <td><p align="center"><i><b><a
> >
href="?sort=author,%20title">Author</a></b></i></td>
> > <td><p
align="center"><i><b>Title</b></i></td>
> > <td><p align="center"><i><b><a
href="?sort=id">Stock
> Num.</a></b></i></td>
> > </tr>
> > <% @books.each do |book| %>
> > <tr>
> > <td><%= book.author %></td>
> > <td><%= book.title %></td>
> > <td><%= link_to book.id, :action => "edit", :id
=> book.id %></td>
> >
> > </tr>
> > <% end %>
> > </table>
> > <% else %>
> > No query specified or no matches
> > <% end %>
> > </div>
> >
> > </body>
> > </html>
> > _______________________________________________
> > Rails mailing list
> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails