How to link_to a file out side rails application


#1

I want to link to a file outside rails application. It is a text file
stored in rails server disk. When user click this link, the file will be
open.

How can I do this?

thanks.


#2

That’s a good question, and I’ll let someone else handle it as I leave
work tonight.

However, I might recommend probably starting up one thread on the
mailing list and asking your questions in there. Will be easier to
keep track of them if they are all in one place. Thanks!


#3

Hi,

Try this :

<%= link_to “file”, “http://www.mysite.com/the_file.doc” %>

Regards,
Rob


#4

Rob Zolkos wrote:

Hi,

Try this :

<%= link_to “file”, “http://www.mysite.com/the_file.doc” %>

Regards,
Rob

My problem is that the file is not in Rails application. There is on
“http://” start. I just want to point to a local file in the server hard
disk. For example: <%= link_to “file”, “/tmp/hello.txt” %>


#5

hi Zhao,

u can use send_file to relate the file in u’r file system but not in
public dir of u’r rails proj like,

send_file(RAILS_ROOT+"/images_uploaded/"+params[:filename] ,
:disposition => ‘inline’)

-manmay

On Thu, Jan 22, 2009 at 10:58 AM, Zhao Yi
removed_email_address@domain.invalid wrote:

My problem is that the file is not in Rails application. There is on
“http://” start. I just want to point to a local file in the server hard
disk. For example: <%= link_to “file”, “/tmp/hello.txt” %>

Posted via http://www.ruby-forum.com/.


M@nmay
http://manmays.googlepages.com
http://manmays.blogspot.com


#6

Manmay wrote:

hi Zhao,

u can use send_file to relate the file in u’r file system but not in
public dir of u’r rails proj like,

send_file(RAILS_ROOT+"/images_uploaded/"+params[:filename] ,
:disposition => ‘inline’)

I have tried but got undefined method `send_file’ for
#ActionView::Base:0x41222cc0 error, this is my code in *.html.erb:

<%= send_file ('/tmp/log.txt', :disposition => 'inline')

#7

MaD wrote:

try to put send_file in an action of your controller.
http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M000167&name=send_file

I use link_to to an action and in this action I use send_file method. In
this action, how can I get the value of the link_to tag?


#8

what kind of value do you need?
you can set :params => {:key => :value} and read them in your
controller.


#9

try to put send_file in an action of your controller.
http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M000167&name=send_file