Hi All,
This post is related to Rails, I have 2 questions:
1.I have an array of fileNames of images in the controller and I want to paginate the images, say 20 images per page. I got the images from Dir.glob.
2.I need to zip a large number of file, thus, to show the user the progress of zipping, I created a link:
<%= link_to_remote("download selected",
:update => nil,
:loading => "Element.show('progress')",
:complete => "Element.hide('progress')",
:url => { :action => :download }) %>
</td>
in the controller for download,
I do the zipping part and after the zip is done, I do a send_file
but, I do not get the "downlaod as" dialog box in the browser.
Howvevr, if i use link_to, I do get the download. But, I wanted to show the progress of zipping as it could involve large number of file.
Regards
Gnan
This could probably be more readable/efficient:
module Enumerable
def paginate(size)
i = 0
self.inject( ) { |arr,item|
(arr[i/size] ||= ) << item
i += 1
arr
}
end
end
[1,2,3,4,6,7,8,9].paginate(4) #=> [[1,2,3,4],[5,6,7,8],[9]]
-Levin
···
Gnanavel <gnanavel.s@gmail.com> wrote:
1.I have an array of fileNames of images in the controller and I want to paginate the images, say 20 images per page. I got the images from Dir.glob.
enumerator module in std. lib has #each_slice (and #each_cons ) methods
to do this "pagination" (take x items at a time from array Y) for you
http://www.ruby-doc.org/stdlib/libdoc/enumerator/rdoc/
Gnanavel
(Gnanavel)
22 August 2005 06:11
4
Hi,
thanks for the response, can this be combined with Ajax pagination helper?
regards
Gnan
"Levin Alexander" <levin@grundeis.net> wrote in message
news:op.svvgufi35gefrg@mail.grundeis.net...
1.I have an array of fileNames of images in the controller and I want to
paginate the images, say 20 images per page. I got the images from
Dir.glob.
This could probably be more readable/efficient:
module Enumerable
def paginate(size)
i = 0
self.inject( ) { |arr,item|
(arr[i/size] ||= ) << item
i += 1
arr
}
end
end
[1,2,3,4,6,7,8,9].paginate(4) #=> [[1,2,3,4],[5,6,7,8],[9]]
-Levin
···
Gnanavel <gnanavel.s@gmail.com> wrote: