You are here: Forums Ask a Rails expert will_paginate, search and ajax...
Posted in Forums : Ask a Rails expert
Authority 12
Posting Rating 0
Sign in to rate this post
|
Hi, I’m using mislav’s excellent will_paginate. I’m trying to achieve a I’ve implemented the guidelines on http://weblog.redlinesoftware.com/2008/1/30/willpaginate-and-remote-links but I’m having a wee bit of bother, since I’m not too sure how to submit the search via ajax, and my pagination link updates the whole page layout and all in the container div. Which I think is something to do with not having a route for the search action (search?page=2) Any help welcome.
Controller
def index
sort_init 'company_registered_number'
sort_update
# @companies = Company.paginate(:page => params[:page], :per_page => 15,:conditions => ['id != 0'], :order => 'company_registered_number ASC')
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @companies}
end
end
def search
respond_to do |format|
format.html { render :partial => 'contents', :layout => false }
end
end
container partial
<div id="container">
<% for company in @companies %>
<tr>
<td class="companyno"><%=h company.company_registered_number %></td>
<td class="companyname"><%= link_to company.company_name, :action => "show", :id => company.id %></td>
<td class="companycity"><%=h company.city %></td>
<td class="companycountry"><%=h company.country.country %></td>
<% if current_user.role.role_description.downcase == 'administrator' %>
<td><%= link_to 'Show', [:admin,company] %></td>
<td><%= link_to 'Edit', edit_admin_company_path(company) %></td>
<td><%= link_to 'Destroy', [:admin,company], :confirm => 'Are you sure?', :method => :delete %></td>
<% else %>
<td><%= link_to 'Show', [company] %></td>
<% end %>
</tr>
<% end %>
<%= will_paginate @collection, :renderer => 'RemoteLinkRenderer', :params => {:action => 'search', :search_terms => params[:search]}, :remote => {:update => 'container'} %>
</div>
index.html.erb
<h1>Listing companies</h1>
<fieldset><legend>Filter</legend>
<% form_tag request.path, :method => 'get' do %>
<% content_tag :label do %>
Search term:
<%= text_field_tag :search, params[:search] %>
<% end %>
</fieldset>
<table>
<tr>
<%= sort_header_tag('company_registered_number',:text => 'Reg Number',:title => 'Sort by Company Number',:class => 'width20 listingheading') %>
<%= sort_header_tag('company_name', :text => 'Name',:class => 'width30 listingheading') %>
<%= sort_header_tag('City',:class => 'width20 listingheading') %>
<%= sort_header_tag('country_id',:text => 'Country',:class => 'width20 listingheading') %>
</tr>
<% if @companies.size != 0 %>
<%= render :partial => 'contents' %>
<% else %>
<p class="norecordsindb">There are no companies in the database to display</p>
<% end %>
<% end %>
</table>
|
Ask a Rails expert : Ruby Builder
Ask a Rails expert : Better programming skills
Ask a Rails expert : Select Option
Ask a Rails expert : Updating ruby version on windows
Ask a Rails expert : Periodicall Ajax Calls and Session Expiry
Ask a Rails expert : Sub queries in RoR
Ask a Rails expert : Remembering associations
Ask a Rails expert : Keeping the databse clean
Ask a Rails expert : How to redirect single app to 2 different URLs
Ask a Rails expert : Dealing with nested models