I have an application in which I create a file in the controller, and
then in the view I want to be able to provide a link to that file for
the user. (the file could be a .doc, or .pdf, say)
In the controller I do something like this:
@foo = ‘foo.doc’
foofile = File.new(@foo, ‘w’)
… write info to file, and then close it
In the view, I have tried every which way to provide a link ‘foo.doc’
but without success.
For example, if I just put in the HTML for the file it gets resolved
something like “localhost:3000/foo.doc” and then I get an error because
that isn’t an action.
many thanks in advance for any help you can give.
I have an application in which I create a file in the controller, and
then in the view I want to be able to provide a link to that file for
the user. (the file could be a .doc, or .pdf, say)
In the controller I do something like this:
@foo = ‘foo.doc’
foofile = File.new(@foo, ‘w’)
… write info to file, and then close it
Hrmm… not sure where “foo.doc” is going to get written out to since
that’s relative to something, but odds are it’s probably not what you
want…
foo = File.join(RAILS_ROOT, ‘public’, ‘foo.doc’)
foofile = File.new(foo, ‘w’)
… write into file and close it…
In your view…
<%= link_to “my file is here”, “/foo.doc” %>
Not that I would recommend you put all your files into public, but the
above should work… at the very least put them into a sub directory
(ie.
/public/files or something).
-philip