Wednesday, September 24, 2008

observe_field Example - Ruby on Rails

<table>
<tr>
<td><label for="searchtext"><font size="1"><b>Live Book Search:</b></font></label></td>
<td><%= text_field_tag :searchtext %></td>
<td><img alt="spinner" id="spinner" src="/images/spinner.gif" style="display:none;" /></td>
</tr>
</table>

<%= observe_field 'searchtext', :frequency => 0.5,
:update => 'search_hits',
:loading => "Element.show('spinner')",
:complete => "Element.hide('spinner')",
:url => { :controller => 'books', :action=> 'live_search' },
:with => "'search=' + escape(value)" %>

<div id="search_hits">
<table>
<tr>
<th>Name</th>
<th>Author</th>
<th>Price</th>
<th>Desc</th>
</tr>

<% for book in @books %>
<tr>
<td><%=h book.name %></td>
<td><%=h book.author %></td>
<td><%=h book.price %></td>
<td><%=h book.desc %></td>
<td><%= link_to 'Show', book %></td>
<td><%= link_to 'Edit', edit_book_path(book) %></td>
<td><%= link_to 'Destroy', book, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

For more detail go to
Wiki.rubyonrails.org

No comments:

Post a Comment

Contact Me for any help regarding rails/nodejs/php/mysql

Name

Email *

Message *