Forum: Ruby on Rails file upload -> save outside the rails project..

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sergio T. R. (Guest)
on 2009-04-17 00:54
i currently have an app that uploads a file and saves it into the file
system..

the one thing i cannot figure out how to do is save it outside the
project..

for instance..

it currently uploads it to:

~/rails_project/public/upload

i would like it to upload to:


~/public_html/upload

any ideas on how to phrase this?

thanks!
Jack B. (Guest)
on 2009-04-17 01:07
In order for it to be saving where it's saving, RAILS_ROOT is probably
being specified in there somewhere. Remove that and add the directory
yourself to /home/user/public_html/upload or whatever it may be.
Sergio T. R. (Guest)
on 2009-04-17 16:26
Jack B. wrote:
> In order for it to be saving where it's saving, RAILS_ROOT is probably
> being specified in there somewhere. Remove that and add the directory
> yourself to /home/user/public_html/upload or whatever it may be.

i did just that.. i specified:

~/public_html/upload

and what it does is.. creates a directory in the rails project called
"~" and puts the files in it..

very strange..
Jacob Basham (Guest)
on 2009-04-17 17:19
(Received via mailing list)
On Fri, 17 Apr 2009, Sergio R. wrote:
> i did just that.. i specified:
>
> ~/public_html/upload
>
> and what it does is.. creates a directory in the rails project called
> "~" and puts the files in it..
>

Did you try expanding the path?
File.expand_path("~/public_html/upload")

jake
Raul M. (Guest)
on 2009-04-17 18:14
Jacob Basham wrote:
> On Fri, 17 Apr 2009, Sergio R. wrote:
>> i did just that.. i specified:
>>
>> ~/public_html/upload
>>
>> and what it does is.. creates a directory in the rails project called
>> "~" and puts the files in it..
>>
>
> Did you try expanding the path?
> File.expand_path("~/public_html/upload")
>
> jake

What about a softlink??
Sergio T. R. (Guest)
on 2009-04-17 18:17
>
> Did you try expanding the path?
> File.expand_path("~/public_html/upload")

perfect! this works great..

thanks!
Sergio T. R. (Guest)
on 2009-04-17 18:18
>
> What about a softlink??

the only reason i shy away from a softlink is that i am using
git/capistrano for development.. i would rather have my paths well
defined..

thanks!
Brendon W. (Guest)
on 2009-04-17 18:28
(Received via mailing list)
Be careful here.  Expanding "~" depends on who is running the Rails
code and in production it often is either the user that runs the web
server or another "not real" user.  (A good thing for security)  So
you want to either put an absolute path OR put a path relative to
RAILS_ROOT if you can ensure that permissions will be OK.

Just remember that this may not work in Production.

Brendon.

On Apr 17, 7:17 am, Sergio R. <removed_email_address@domain.invalid>
Sergio T. R. (Guest)
on 2009-04-17 18:35
> Just remember that this may not work in Production.
>
> Brendon.

thanks!

i just checked..

here's how i have this set up..

the app runs as a user, inside that user's home directory..

the files are saved to that same user's ~/public_html directory.. via a
subdomain:

files.domain.com

..

so permissions work out correctly..

thanks!
This topic is locked and can not be replied to.