开发者

ruby can't convert Array into String error

I am trying to do this zip thing

http://blog.devinterface.com/2010/02/create-zip-files-on-the-fly/

However, I got a bit confussion with returning the path of files using path method that returns the file inside a folder.

    开发者_JS百科   def download_zip(image_list)
       . . .
       image_list.each do |img|
       z.put_next_entry(title)
       z.print IO.read(img.path)
       end

my confussion is with the z.print IO.read(img.path). Meeans that I need to have a path method in the mode of image_list (isn't it?). I wrote down this path method

        def path
        @files = Dir.glob("C:/myfolder/me/*") 
        @files
        end

where I have some files inside the "me folder" that I need to return to z.print IO.read(img.path) but I got an error of can"t convert array into string. Can anyone point out how to do the path method that can return the files and avoiding the array into string problem? I tried to use File.open instead of Dir.glob, and got permission error in windows.

Thank you for any response


Your image_list should be an array of images, each of which implements at least two methods - path and title. A single image only has a single path - where are you trying to add that path method? It looks like you are trying to add it to image_list, which is a wrong place.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜