richardhellyer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-22 06:52 UTC
Simple Link to Static File
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 itHrmm... 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> > 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. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---