I would like to refer to a file location outside my rails project.
Main Topics
Browse All TopicsHow to create a html link to a file outside rails application directory using ActionView?
I am trying to render a file stored in my /tmp directory using render or link_to methods of action view. I would like to open this link in a new browser tab or window.
When I use render or send_file method from controller then it does point to file in/tmp directory. However, this does not work from view. The rails looks for this file within view dir. How can I override this/ specify absolute path?
Missing template /tmp/test.html in view path /home/gt9/NetBeansProjects
Thanks,
GT.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
so something like
<%= link_to "test", "file:///C:/tmp/test.htm" l%>
or
<%= link_to "test", "http://localhost/test.htm
this is the olny way I can think to do it
You can't link directly to a file outside of the /public directory. That's the only directory served by the webserver!
However, you can read the file in and send it as a stream to the browser. I use this technique for creating a pdf and then sending it to the browser.
Your link will actually be to an action that grabs the file and sends it. Don't pass the path and filename into the action or someone could grab any file they want off your system!
Check out the API for the ActionController::Streamin
http://api.rubyonrails.com
Specifically, you probably want send_file()
I am trying to develop a similar feature, although I am generating text and html content from MS Word files. I can render these files using render and send_file methods. However, I would like these files to be rendered in a new tab or a new window. I did not see any options for doing this with ActionController methods. The link_to method offers this option to me.
Is there any way I can open a new tab using render or send_file methods?
Thanks,
GT.
Posted related question: http://www.experts-exchang
~
GT
Business Accounts
Answer for Membership
by: doadesPosted on 2008-10-19 at 06:46:17ID: 22752174
something like this?
<%= link_to "test", "/tmp/test.html" %>
this looks to a folder called tmp under the public folder!