Newbie: how to use link_to to create ftp url to download a file?

Hi everyone,

I'm struggling with link_to. I'm trying to generate a link that will enable my web users to ftp a file.

Table 'calls' contains a field 'filename'. There the requirement to download this file via ftp.

For example: calls.filename = '/project/tmp/file/README.txt'

should convert to <a href="ftp:///project/tmp/file/README.txt">/project/tmp/file/README.txt</a> (or whatever the number of slashes is after 'ftp:')

Thanks, Birgit

Hi,

I realise there is one more issue here. The 'calls' table also contains the ip address of the machine that hosts the file.

So calls.ip_address = 123.456.789.123

This should find its way to the ftp url as well: ftp://123.456.789.123/project/tmp/file/README.txt

Thanks, Birgit

Hi,

I realise there is one more issue here. The 'calls' table also contains the ip address of the machine that
hosts the file.

Do the :protocol and :host options help you?

Fred

Hi Fred,

Thanks for your help. I've seen :protocol and :host. I'm more struggling what to do with call.filename itself?

If "call.filename" is the value, what is the key that goes with it? <%= link_to call.filename,    {:protocol => 'ftp', :host => call.ip_address} %>

Thanks, Birgit

Hi Everyone,

For those who might struggle like myself, this is how I solved my problem in the end.

I added a helper method to my call model, called to_url(): def to_url(call)      if (call.filename) then          uri2 = URI::FTP.build({:host => call.ip_address,                  :path => call.filename})          uri2.to_s      else          ''      end end

In my index view, I call: <%= link_to call.filename, to_url(call) %>

Cheers, Birgit