开发者

problem show text (from name files) inside ruby shoes

first..sorry for my poor english and my big noob question..the problem is...

I need create a little shoes app than show the excel files inside a folder (this is only a part)...I define a method like this:

def sh开发者_StackOverflow中文版ow_proov
  files = Dir.new(personal_folder).entries
  xlsxfiles = files.find_all {|file| file.include?('.xlsx') }.map do |file| file.scan(/^\w+/) end
end

if I show in a alert it..it works and shows the files...so far so good: now..the problem is than I wish iterate over this names and create a menu..when I try it I get a error related about "bad encode" (sorry but I've tried recreate this code but I never get this message again)

well..no problem...maybe a list_box could do the work:

inside my shoes app I define list_box :items => show_proov doing that..nothing is render inside the windows...don't show anything

the same happen if I use

@items=show_proov
#@items.class = array
list_box :items => @items

it hasn't much sense but I must has the try...

thanks for read and for help!! :D


I think your problem might be that your show_proov function is returning an array of arrays.

[["file1"], ["file2"], ["file3"]]

This is because String.scan returns an array. Try adding .first, like so:

  xlsxfiles = files.find_all {|file| file.include?('.xlsx') }.map do |file| file.scan(/^\w+/).first end

Then the result will be:

["file1", "file2", "file3"]


if you get somethinbg from excel the encoding is different, so use

.force_encoding("UTF-8")

on the string you get from ecel before manipulating it. Cheers

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜