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
public/attachments/<user_id>/<profile_id>
which would end up being something like
public/attachments/23/18
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
we get
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
Dale
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Jan 25, 9:20 am, "PeteSalty" <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> We want to save the attachments into a directory > structure like this > > public/attachments/<user_id>/<profile_id> > > which would end up being something like > > public/attachments/23/18Are you trying to create the directory structure 23/18/ in one fell swoop? Because the standard Dir.mkdir will only make a single directory at a time. If you want to create all of the directories necessary for your path in one go, you can use FileUtils.mkdir_p: http://www.ruby-doc.org/stdlib/libdoc/fileutils/rdoc/classes/FileUtils.html#M000528 which is equivalent to the ''mkdir -p'' command at the shell. Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris, Thank you so much for pointing this out, that certainly saved the day. Dale On Jan 25, 1:32 am, "Chris Mear" <c...-OIzkuoyqg0kAvxtiuMwx3w@public.gmane.org> wrote:> On Jan 25, 9:20 am, "PeteSalty" <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > We want to save the attachments into a directory > > structure like this > > > public/attachments/<user_id>/<profile_id> > > > which would end up being something like > > > public/attachments/23/18Are you trying to create the directory structure 23/18/ in one fell > swoop? Because the standard Dir.mkdir will only make a single directory > at a time. > > If you want to create all of the directories necessary for your path in > one go, you can use FileUtils.mkdir_p: > > http://www.ruby-doc.org/stdlib/libdoc/fileutils/rdoc/classes/FileUtil... > > which is equivalent to the ''mkdir -p'' command at the shell. > > Chris--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---