Rails controller download file






















Improve this question. Aaron Vegh Aaron Vegh 5, 7 7 gold badges 46 46 silver badges 72 72 bronze badges. Add a comment.

Active Oldest Votes. Improve this answer. Jason stewart Jason stewart 1, 8 8 silver badges 8 8 bronze badges. Interesting idea! Having played around with this, I'm having trouble getting it to work. The cookie can be set in the controller action, but it won't be checked until the page reloads.

So I can download the file and nothing happens. But when I manually refresh the page, boom! Interval checking kicks in and detects the cookie. Yes, I got it working! Great answer, thanks very much! Sign up or log in Sign up using Google. Sign up using Facebook. Add a comment. Active Oldest Votes. Should work when the file is placed correctly. Let me know if you can't move your file to public folder. Improve this answer. I'm pretty sure all resources should be placed in the assets folder since rails 3 but since it worked it will do for now.

Sorry it was not specified which version of rails you were using — felipeclopes. Check the new edit I just made for Rails 3. Hope it helps you!

No need for this approach if those pdf's are available to everyone. With Rails 3. Navi I tried your approach but I keep getting the No route matches error. Can you see the issue here? How would you adjust this for multiple files? IE a folder of files one was generating links to in a list — Btuman. Show 1 more comment. If the files are static meaning they don't change , place them in the public folder.

Cruz Nunez Cruz Nunez 2, 1 1 gold badge 20 20 silver badges 32 32 bronze badges. Active Oldest Votes. Improve this answer. Nick 8, 6 6 gold badges 41 41 silver badges 65 65 bronze badges. I only want to set the filename, rather than redefine the whole action. I guess the thing is you're requesting a URI with a format. I would expect it to return a document with that name. Did you see my other suggestion? Grant Neufeld Grant Neufeld 1 1 gold badge 9 9 silver badges 16 16 bronze badges.

Thanks, this answer helped me answer my own question. Roberto Trevisan Roberto Trevisan 1 1 silver badge 9 9 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.



0コメント

  • 1000 / 1000