I’m devloping an application that allows users to attach files to their
profiles. At the moment they can only attch one file per profile. We
have some unique requirements so we have to write our own code for this
(can’t use act_as_attachment or file_column).
Anyhoo, we’ve got pretty much everything working except one really
bizzare problem. We want to save the attachments into a directory
structure like this
which would end up being something like
the only problem is that when we try to either open the file for
writting with something like
File.open(@save_location + '/' + @file_name, "wb") do |f| f.write(@temp_file.read) end
No such file or directory - public/attachments/23/18/test-file.jpg
or try and make a new directory using
Dir.mkdir(@save_location) unless File.directory?(@save_location)
we get the folowing error:
No such file or directory - public/attachments/23/18
or something similar depending on the user_id and profile_id of course.
This is happening on my development machine and I have to admint I
haven’t tried it on another (don’t have another set up or available at
this time) but I can’t seem to work out why it won’t create the
directories. If I try it with just say
File.open('public/attachments/' + @file_name, "wb") do |f| f.write(@temp_file.read) end
it works fine however in this case both ‘public’ and ‘attachments’
already exist so I’m guessing it’s got something to do with creating
the new directories.
Any ideas? Could it have something to do with the public directory
being under Subversion (although the attachments directory is not).
Thanks in advance