Hi,
I implemented the partial, in order to make a live search with Ajax.
Both works, but there is a problem - my records are a set of rows in a
table, and the table has some header and footer data (with <th> tag),
that I need to show with the filtered (searched) set of records also.
It initially shows fine from the ''list'' action (when no
filtering/
search is done). But after I type something in the search box, the
results are returned ok, but no synchronozation with the table.
I call the partial from my view, and have a method ''search'' in
my
controller:
def search
items_per_page = 10
@server_pages, @servers = paginate :servers,
:order => ''server_name'',
:per_page => items_per_page,
:conditions => ["lower(server_name) like ?", "%" +
params[:search].downcase + "%"]
if @servers.size > 0
render :partial => ''server'', :collection => @servers
else
render :text => "<li>No results found</li>",
:layout => false
end
end
Here is the partial ''_server.rhtml'':
<tr class="<%= cycle("record",
"even-record") %>" >
<td><%= server.server_name -%></td>
<td><%= server.server_type.server_type_desc -%></td>
<td><%= server.platform.platform_name -%></td>
<td><%= server.environment.environment_name -%></td>
<td><%= link_to ''Edit'', {:action =>
"edit", :server_id =>
server.server_id} %></td>
<td><%= link_to "Delete", {:action =>
''delete'', :server_id =>
server.server_id},
:confirm => "Are you sure you want to delete this
Server?"
%></td>
<td><%= link_to ''App Servers'', {:action =>
"show_app_servers", :server_id => server.server_id}
%></td>
<td><%= link_to ''DB Servers'', {:action =>
"show_database_servers", :server_id => server.server_id}
%></td>
<td><%= link_to ''DB Conns'', {:action =>
"show_db_conns", :server_id => server.server_id} %></td>
</tr>
And lastly, here is the view ''list.rhtml'':
<%= text_field_tag :searchQuery %>
<img id="search-icon" src="/images/search-icon.gif"
style="display:
none;" />
<div id="table">
<table cellpadding="0" cellspacing="0">
<tr class="header-row"><th
colspan="100">Servers</th></tr>
<tr class="header-row">
<th>Server Name</th>
<th>Server Type</th>
<th>Platform</th>
<th>Environment</th>
<th colspan="5"></th>
</tr>
<%= render :partial => ''server'', :collection =>
@servers %>
</table>
</div>
<%= observe_field( :searchQuery, :frequency => 0.5,
:update => ''table'',
:before => "Element.show(''search-icon'')",
:success => "Element.hide(''search-icon'')",
:url => { :controller => ''server'', :action=>
''search'' },
:with => "''search='' + encodeURIComponent(value)"
) %>
Having tough time... Anybody could help please?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---