近来碰到一个问题
想遍历某个目录下的所有文件
但是发现写了这段程序后
Dir.chdir("#{RAILS_ROOT}" + "/public/images")
@dirs = Dir["*"]
@dirs = Dir["*"]
报了莫名其妙的错 Application Error
后来查了下资料 在windows下 RAILS_ROOT是相对路径,而我们需要一个绝对路径,在使用chdir的时候
因此可以在boot.rb文件中修改如下
在 root_path = File.join(File.dirname(__FILE__), '..') 一行下面增加一行:
root_path = File.expand_path(File.join(File.dirname(__FILE__), '..')
)
然后重启web服务既可解决这个问题