will_paginate 在rails3中生成转义的html,raw和.html_safe似乎没有帮助
will_paginate 生成转义的 html,我在这里缺少什么。我已经验证 will_paginate 生成了 html_save 代码,我也尝试添加 will_paginate(@pictures).html_safe 。请注意,page_entries_info 按其应有的方式工作,它只是混乱的主要帮助程序。目前我已经手动完成了代码,但出于明显的原因,我更愿意为此使用适当的帮助程序。
控制器:
class PicturesController < ApplicationController
# GET /pictures
# GET /pictures.xml
def index
@pictures = Picture.recent.paginate(:page => params[:page], :per_page => 4)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @pictures }
end
end
end
视图:
<% @pictures.each_with_index do |picture, i| %>
<%= link_to(picture_image_tag(picture, "small"), picture, :class => "picture grid_2 " + nine_sixty_alpha_omega(i, 4)) %>
<% end %>
<div class="clear"></div>
<%=raw will_paginate(@pictures) %>
<%= @pictures.total_pages %>
<%=raw page_entries_info(@pictures) %>
Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.0.beta3'
gem "mongoid", "2.0.0.beta4"
gem "bson_ext", "0.20.1"
gem 'will_paginate', '3.0.pre', '>= 3.0.pre'
#gem 'agnostic-will_paginate'#, :require => 'will_paginate'
gem 'mongo'
输出:
<span class="disabled prev_page">&laquo; Previous</span> <span class="current">1</span> <a href="/pictures?page=2" rel="next">2</a> <a href="/pictures?page=2" class="next_page" rel="next">Next &raquo;</a>
2 Displaying pictures 1 - 4 of 6 in total
will_paginate produces escaped html, what am I missing here. I've verified that will_paginate producted html_save code, I've tried adding will_paginate(@pictures).html_safe as well. Note that page_entries_info works as it should, its just the main helper that is messed up. For the time being I've done the code manually, but for obvious reasons I would prefer to use the proper helper for this.
controller:
class PicturesController < ApplicationController
# GET /pictures
# GET /pictures.xml
def index
@pictures = Picture.recent.paginate(:page => params[:page], :per_page => 4)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @pictures }
end
end
end
view:
<% @pictures.each_with_index do |picture, i| %>
<%= link_to(picture_image_tag(picture, "small"), picture, :class => "picture grid_2 " + nine_sixty_alpha_omega(i, 4)) %>
<% end %>
<div class="clear"></div>
<%=raw will_paginate(@pictures) %>
<%= @pictures.total_pages %>
<%=raw page_entries_info(@pictures) %>
Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.0.beta3'
gem "mongoid", "2.0.0.beta4"
gem "bson_ext", "0.20.1"
gem 'will_paginate', '3.0.pre', '>= 3.0.pre'
#gem 'agnostic-will_paginate'#, :require => 'will_paginate'
gem 'mongo'
Output:
<span class="disabled prev_page">« Previous</span> <span class="current">1</span> <a href="/pictures?page=2" rel="next">2</a> <a href="/pictures?page=2" class="next_page" rel="next">Next »</a>
2 Displaying pictures 1 - 4 of 6 in total
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我一直在使用较新版本的 will_paginate 和 Rails,没有任何问题。
您可以尝试 kaminari,因为它更适合 Rails 3。
I've been using newer versions of will_paginate and Rails with no problems.
You could try kaminari, as it's better suited for Rails 3.