Odpowiedź Tomha jest prawidłowa. Tylko dla shiggles, prototypowałem szybką implementację. Here's a screencast, który pokazuje to za pomocą Ajax, gdy JavaScript jest włączony (twoi użytkownicy) i nadal ma ładne adresy URL, gdy JavaScript jest wyłączony (Google). Oto kilka fragmentów kodu, które pozwolą Ci je przetasować.
config/routes.rb:
map.connect 'items/:page', :controller => "items", :action => "index", :page => 1
app/controllers/items_controller.rb:
class ItemsController < ApplicationController
def index
@items = Item.paginate(:all, :page => params[:page])
respond_to do |format|
format.html
format.js do
render :update do |page|
page.replace_html :items, :partial => "items"
page << "ajaxifyPagination();"
end
end
end
end
end
app/views/items/index.html.erb:
<h1>Listing items</h1>
<div id="items">
<%= render :partial => "items" %>
</div>
app/views/items/_items.html.erb:
<%= will_paginate @items %>
<table>
<% for item in @items %>
<tr>
<td><%= item.id %></td>
</tr>
<% end %>
</table>
układ:
<%= javascript_include_tag :defaults %>
public/javascripts/application.js:
$(document).ready(function() {
ajaxifyPagination();
});
function ajaxifyPagination() {
$(".pagination a").click(function() {
$.ajax({
type: "GET",
url: $(this).attr("href"),
dataType: "script"
});
return false;
});
}
Mój przykład używa jQuery (z jRails), ale jest to proste do zrobienia z Prototype, jak również.
W rzeczywistości to pytanie jest teraz pierwszym ogniwem; – ted