문제

i have built this little app that generates a excel document. i am trying to make a directory to stick it in. these documents are built differently depending on the @agency that people select. so i made this method to return the path since the path is used in a few places.

def reportsheet_dir
  file_path = "#{Rails.root}/public/reportsheets/#{@agency.downcase.gsub("_","")}"
end

At the beginning of the method that creates the document i have this method that supposedly builds directories but it doest seem to be working

Dir.mkdir(reportsheet_dir) unless File.exists?(reportsheet_dir)

I keep getting. this and i get

Errno::ENOENT at /addons/agency_report_builders 
No such file or directory -/Users/fortknokx/Work/toolkit/public/reportsheets/empowerlogicbuilder

I think its because its multiple levels deep?? since public/reportsheets/agency_name/file_name has to be made. i could just go and make the folders but i would like to just make the dir each time because new agencies could be made at any time. is this possible?

도움이 되었습니까?

해결책

Have a look at FileUtils.mkdir_p()

http://ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/FileUtils.html#method-c-mkdir_p

It will recursively create non-existent directories. Dir.mkdir will not.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top