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
/project/tmp/file/README.txt
(or whatever the number of slashes is after ‘ftp:’)

Thanks, Birgit


– Birgit A., [email protected],
– Westhawk Ltd, Albion Wharf, 19 Albion Street, Manchester M1 5LN, UK
– Company no: 1769350
– Registered Office:
– 15 London Road, Stockton Heath, Warrington WA4 6SJ. UK.
– tel.: +44 (0)161 237 0660
– <URL: http://www.westhawk.co.uk>

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

On 17/07/08 13:34, Birgit A. wrote:

should convert to
/project/tmp/file/README.txt
(or whatever the number of slashes is after ‘ftp:’)

Thanks, Birgit


– Birgit A., [email protected],
– Westhawk Ltd, Albion Wharf, 19 Albion Street, Manchester M1 5LN, UK
– Company no: 1769350
– Registered Office:
– 15 London Road, Stockton Heath, Warrington WA4 6SJ. UK.
– tel.: +44 (0)161 237 0660
– <URL: http://www.westhawk.co.uk>

On 17 Jul 2008, at 13:38, Birgit A. wrote:

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

On 17/07/08 13:56, Frederick C. wrote:

Do the :protocol and :host options help you?

For example:


– Birgit A., [email protected],
– Westhawk Ltd, Albion Wharf, 19 Albion Street, Manchester M1 5LN, UK
– Company no: 1769350
– Registered Office:
– 15 London Road, Stockton Heath, Warrington WA4 6SJ. UK.
– tel.: +44 (0)161 237 0660
– <URL: http://www.westhawk.co.uk>

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

On 17/07/08 14:54, Birgit A. wrote:

Thanks, Birgit

Thanks, Birgit

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

should convert to
/project/tmp/file/
README.txt
(or whatever the number of slashes is after ‘ftp:’)

Thanks, Birgit


– Birgit A., [email protected],
– Westhawk Ltd, Albion Wharf, 19 Albion Street, Manchester M1 5LN, UK
– Company no: 1769350
– Registered Office:
– 15 London Road, Stockton Heath, Warrington WA4 6SJ. UK.
– tel.: +44 (0)161 237 0660
– <URL: http://www.westhawk.co.uk>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs