Tuesday, July 27, 2010

Ruby on Rails : Ajax : link_to/form_for onclick loading effect

Link with Ajax loading image in view.rhtml:


<div id="showlist">

<%= link_to_remote "Search",
:url => { :action => "create" },
:update => "showlist",
:loading => "document.getElementById('spinner').style.visibility='visible';" %>

<img src="http://www.insight24.com/view/insight24/img/loading.gif" style="visibility:hidden;" id="spinner">

</div>



Form with Ajax loading image in view.rhtml:


<% remote_form_for :search, @search,
:url => {:action => 'create'},
:loading => "document.getElementById('spinner').style.visibility='visible';",
:update => "showlist" do |f| %>

Keyword: <%= text_field 'search', 'item' %><%= submit_tag "Search"%>
<img src="loading.gif" style="visibility:hidden;" id="spinner">
<% end %>

<div id="showlist"></div>


See also: Simple Ajax Search Engine

2 comments: