Link_to download file from path over public

I have restricted files that I want to share, I want to place the files
in a path over public but don’t know how to link to that file?

/Daniel

On 18 Dec 2006, at 11:40, haze wrote:

I have restricted files that I want to share, I want to place the
files
in a path over public but don’t know how to link to that file?

If you’re using Capistrano, I suggest you place your files in:

/path/to/your/app/shared/public/files/

And then create an after_symlink deployment task to symlink /path/to/
your/app/current/public/files/ to your shared files directory. The
RailsMachine gem does this so look there if you need the exact code.

You can then reach them in the browser at, say, http://your.app/files/
your_file.txt

In your controller, you can reach them with, say, send_file ‘public/
files/your_file.txt’.

Regards,
Andy S.

Andrew S. wrote:

On 18 Dec 2006, at 11:40, haze wrote:

I have restricted files that I want to share, I want to place the
files
in a path over public but don’t know how to link to that file?

If you’re using Capistrano, I suggest you place your files in:

/path/to/your/app/shared/public/files/

And then create an after_symlink deployment task to symlink /path/to/
your/app/current/public/files/ to your shared files directory. The
RailsMachine gem does this so look there if you need the exact code.

You can then reach them in the browser at, say, http://your.app/files/
your_file.txt

In your controller, you can reach them with, say, send_file ‘public/
files/your_file.txt’.

Regards,
Andy S.

Ok but if i symlink to another directory over the public, wont other
users that arent loged in be able to download these files ?

or should i delete the symlink when logout… ?

It maybe sounds litle bit newbe, im not very skilled yet…

/Daniel

On 18 Dec 2006, at 14:23, haze wrote:

Ok but if i symlink to another directory over the public, wont other
users that arent loged in be able to download these files ?

Yes they will. I didn’t realise that you wanted to restrict access.

or should i delete the symlink when logout… ?

That’s messy. Here’s a better way to do it:

  • Make the directory app/shared/private/ on your server. It should
    sit beside the existing app/shared/public/. Make a directory files/
    inside it and stick your files in there.

  • Using Capistrano symlink your app/current/private/ to the shared
    one. For example, add this to your deploy/config.rb:

Automatically symlink these directories from current/private to

shared/private.
set :app_private_symlinks, %w{ files }

desc “Link up any private directories.”
task :symlink_private, :roles => [:app, :web] do
if app_private_symlinks
app_private_symlinks.each { |link| run “ln -nfs #{shared_path}/
private/#{link} #{current_path}/private/#{link}” }
end
end

desc “Creates additional symlinks.”
task :after_symlink, :roles => [:app, :web] do
symlink_private
end

  • In your action, you can do something like:

if @user.logged_in? # or however you determine whether somebody is
logged into your app
send_file ‘private/files/your_file.txt’
end

It maybe sounds litle bit newbe, im not very skilled yet…

Hey, don’t worry about it. Nor am I :slight_smile:

Regards,
Andy S.