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.