Ameba Ownd

アプリで簡単、無料ホームページ作成

Ashley Moody's Ownd

Rails link to download file in public

2021.12.20 17:18






















Active 8 years ago. Viewed 25k times. Improve this question. Richard This seems like a terribly unsafe way to handle this, especially considering you can just link directly to the file.


Andrew - use what? Someone could edit your link like this:? I would be more than happy to hear of the "correct way" for a user to obtain a file!!! Open to any suggestions! Show 3 more comments. Active Oldest Votes. Rather, if the file is under public, link to the file itself. 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. I think this attitude is not right for newbie SO users like me.


Sign up or log in Sign up using Google. Daniel Daniel 4, 8 8 gold badges 33 33 silver badges 47 47 bronze badges.


Daniel If you're trying to access that URI from something other than the front-end of the Rails app, let us know, because that may also be significant. Add a comment. Active Oldest Votes. Improve this answer. Frost Frost 8, 2 2 gold badges 36 36 silver badges 43 43 bronze badges. Frost, I think you might be missing an equals sign right after your first percent symbol. Without that equals sign, nothing will be displayed.


Tass Thank you for noticing. As a result, a lot more of the things that we use and buy are digital items, ones that we download from websites after we pay for them. There will very likely be a time in your career when you will have to build a website that is offering things for sale, digital things.


Ebooks, software downloads, these kinds of things. These things will very likely be stored on the server, waiting for people to purchase them and then download them. But how do you stop people from just being able to download them without paying for them? This works great for the application's assets, it's icons, stylesheets and JavaScripts, but of course, it's not what you want if people, or yourself, are storing digital assets in the application that are for sale.


You will only want these to be available to those who have purchased them. Luckily with Ruby on Rails and Paperclip, this can be achieved without too much difficulty. Let's take a look. First up, you want to install Paperclip in your Rails application, so let's add it to a Gemfile. Now that we have Paperclip in, let's look at what we need to do.


For an application like this, we need a few things. In a production application where you sell digital goods, you will also need to have a way to take payment. That is beyond the scope of what I'm talking about here, but I have written several things on how to accept payments with Stripe , so you can refer to those if you need. Let's quickly run through those ActiveRecord classes. These will just be a bare minimum for you to see how this all works, your classes in your application will undoubtedly store other information as well.


This User class will be for all of our users, both those that want to upload images for sale and those that wish to purchase images. One User would be able to both upload images for sale and purchase images from other users. This migration is made available to us by using Paperclip. It will add all the fields to store all the information we need to know about the image files themselves.