Skip to content

Commit

Permalink
Merge pull request kaminari#134 from sethvargo/master
Browse files Browse the repository at this point in the history
Added documentation for generating friendly URLs
  • Loading branch information
amatsuda committed Jul 2, 2011
2 parents e4e2ef1 + cf1d1ce commit beeb13b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.rdoc
Expand Up @@ -195,6 +195,20 @@ However, the <tt>paginate</tt> helper doesn't automatically handle your Array ob
<tt>Kaminari::paginate_array</tt> method converts your Array object into a paginatable Array that accepts <tt>page</tt> method. <tt>Kaminari::paginate_array</tt> method converts your Array object into a paginatable Array that accepts <tt>page</tt> method.
Kaminari.paginate_array(my_array_object).page(params[:page]).per(10) Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)


== Creating friendly URLs and caching

Because of the `page` parameter and Rails 3 routing, you can easily generate SEO and user-friendly URLs. For any resource you'd like to paginate, just add the following to your `routes.rb`:

resources :my_resources do
get 'page/:page', :action => :index, :on => :collection
end

This will create URLs like `/my_resources/page/33` instead of `/my_resources?page=33`. This is now a friendly URL, but it also has other added benefits...

Because the `page` parameter is now a URL segment, we can leverage on Rails page caching[http://guides.rubyonrails.org/caching_with_rails.html#page-caching]!

NOTE: In this example, I've pointed the route to my `:index` action. You may have defined a custom pagination action in your controller - you should point `:action => :your_custom_action` instead.



== For more information == For more information


Expand Down

0 comments on commit beeb13b

Please sign in to comment.