I have the will_paginate plugin working in an applicati开发者_开发百科on, but when I paginate a resource it just spits out the HTML as text, doesn't provide links to the next pages and such.
And when I manually type in the URL the plugin is working it just doesn't make <%= will_paginate @products %>
into links such as next 1 2 3 ... last
This is the output
<span class="disabled prev_page">&laquo; Previous</span> <span class="current">1</span> <a href="/products?page=2" rel="next">2</a> <a href="/products?page=2" class="next_page" rel="next">Next &raquo;</a>
controller: def index
@products = Product.all.paginate :per_page => 5, :page => params[:page]
@product_categories = ProductCategory.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @products }
end
end
view
<%= will_paginate @products %>
<%= will_paginate %> #for some reasons this works too
source 'http://rubygems.org'
gem 'rails', '3.0.0.beta2'
gem "will_paginate", '3.0.pre'
if you run into troubles related to haml we use that version:
gem 'haml', '3.0.2'
will_paginate is now at this location:
gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch => "rails3"
update your gemfile
I believe the reasons is the ways rails3 escapes html and for whatever reason will_pagiante
is getting escaped.
to fix this you first need to get the correct gem as the plugin won't work so add gem 'agnostic-will_paginate', :require => 'will_paginate'
and that is done in the new gem file located in the app folder of a rails3 project.
After that you need to stop rails from escaping will_paginate with raw
so something like
<%=raw will_paginate @products %>
which is the opposition of <%=h will_paginate @products %>
which in rails3 is equivalent to <%= will_paginate @products %>
WILL PAGINATE MOVED TO GITHUB. This repository is no longer updated. It's recommended that you install the gem instead of a Rails plugin:
gem install will_paginate
and Try Again
精彩评论