使用 will_paginate 单击图像时如何转到下一个记录集
我正在使用 Rails 3 和 will_paginate 来浏览照片。我让它正常工作,但我也希望用户可以通过单击图片而不是分页导航中的下一个按钮来查看下一条记录。与 facebook 图像查看或类似以下内容非常相似: http://exposure.blogocracy.org/ demos/demo1.html
我不知道 will_paginate 是否有任何参数允许其工作...任何帮助或指导将非常感激
控制器 - 图像 - 操作:画廊
def gallery
@images = Image.all.paginate(:per_page => 1, :page => params[:page])
end
视图图像 - 画廊
<div id="slideshow">
<% @images.each do |image| %>
<%= image_tag("gallery/"+image.path, :alt => "") %>
<% end %>
</div>
视图布局 - _nav
<%= will_paginate @images, :previous_label => '« ',
:next_label => '»',
:params => { :controller => "images",
:action => "gallery" },
:separator => ' ',
:inner_window => 4,
:outer_window => -1 %>
-----------编辑--------------
作为解决办法,我决定使用 javascript / jquery 并手动链接它..它真的很难看,但我使用它直到我找到正确的方法。
$(document).ready(function() {
$('div#slideshow img').live('click', function() {
var has_images = '<%= @has_image %>';
if( has_images == 1 ) {
var page = '<%= @next_image.id %>';
var url = '/images/gallery?page='+page
window.location.replace(url);
}
else {
var url = '/images/gallery?page=1'
window.location.replace(url);
}
})
})
I am using rails 3 and will_paginate to browse through photos. I have it working except I would also like it so that users can view the next record by clicking the picture rather than the next button in the pagination navigation. Very similar to facebooks image viewing or something like the following: http://exposure.blogocracy.org/demos/demo1.html
I don't know if will_paginate has any parameters to allow this to work... any help or direction would be very much appreciated
controller - image - action: gallery
def gallery
@images = Image.all.paginate(:per_page => 1, :page => params[:page])
end
view image - gallery
<div id="slideshow">
<% @images.each do |image| %>
<%= image_tag("gallery/"+image.path, :alt => "") %>
<% end %>
</div>
view layout - _nav
<%= will_paginate @images, :previous_label => '« ',
:next_label => '»',
:params => { :controller => "images",
:action => "gallery" },
:separator => ' ',
:inner_window => 4,
:outer_window => -1 %>
-----------EDIT--------------
As a work around I decided to use javascript / jquery and link it manual.. it's really really ugly but im using it until i figure out the right way to do it.
$(document).ready(function() {
$('div#slideshow img').live('click', function() {
var has_images = '<%= @has_image %>';
if( has_images == 1 ) {
var page = '<%= @next_image.id %>';
var url = '/images/gallery?page='+page
window.location.replace(url);
}
else {
var url = '/images/gallery?page=1'
window.location.replace(url);
}
})
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您链接到的示例是一个名为 Exposure 的 jQuery 插件,为什么不直接使用它?
我不会推荐 Will_paginate 来满足您的需求。
奥鲁夫·尼尔森
The example you are linking to is a jQuery plugin called Exposure why don't you just use that?
And i wouldn't recommend Will_paginate for that you want.
Oluf Nielsen