All pastes #401115 Raw Edit

clara

public ruby v1 · immutable
·published 2007-03-19 03:11 UTC
rendered paste body
## HELPER CODEdef pagination_links_remote(paginator)  page_options = {:window_size => 1}  pagination_links_each(paginator, page_options) do |n|    options = {      :url => {:action => 'list', :params => @params.merge({:page => n})},      :update => 'table',      :before => "Element.show('spinner')",      :success => "Element.hide('spinner')"    }    html_options = {:href => url_for(:action => 'find', :params => @params.merge({:page => n}))}    link_to_remote(n.to_s, options, html_options)  end### CONTROLLER   def find    unless @params[:search].nil?      query = "select distinct a.id, a.title      from yourimages a, taggings b, tags c      where (c.id = b.tag_id      and b.taggable_id = a.id      and c.name like '%"+params[:search].downcase+"%')      or a.title like '%"+params[:search].downcase+"%' order by created_at desc"          @search_pages, @tags = paginate_by_sql Yourimage, query, 10      @total = @tags.size    else    end      if request.xml_http_request?        render :partial => "ilist", :layout => false      end  end### VIEW<div class="search"><%= text_field_tag("search", @params['search'], :size => 20 ) %><%= image_tag("indicator-white.gif",              :border=> 0,              :id => "spinner",              :style=>"display: none;" ) %><%= observe_field 'search', :frequency => 2.0, :update => 'searchres',          :before => "Element.show('spinner')",         :success => "Element.hide('spinner')",:url => {:action => 'find'},:with => 'search'%></div><ul id="searchres"><%= render :partial => "ilist" %></ul>### PARTIAL <% if @tags.nil? %><% else %>  <% if @total == 0 %>    <p>No items found...</p>  <% else %><p>      <% unless @params[:search].nil? %><%= pagination_links_remote @search_pages %><%else%><%end%></p>    <% @tags.each do |t| %>      <%= link_to t.title, {:action => 'show', :id => t} -%><br/>    <% end %><% end%><% end%>