Stpn
Stpn

Reputation: 6394

Rails link database entry to local file dynamically

I am downloading files through the Rails app and I need to save the link to the local file (that was downloaded) in a database object..

So if I have

Media name:string url_link:string actual_file:string(??)

How do I define a path to a local file (so that I can also call/load it through rails sometime later)?

say the file is in applications folder (on same level with Gemfile etc..).

Thanks!

Upvotes: 0

Views: 179

Answers (1)

Carl Zulauf
Carl Zulauf

Reputation: 39568

Generally static assets like local files should be in your public directory in your rails app. Then your local path could be relative to your public directory, so the path images/funny.jpg would point to a file called funny.jpg in your_project_folder/public/images/.

However, attaching files to ActiveRecord objects is a wheel that has long since been invented. No sense in reinventing the wheel for your app. Look at paperclip as it provides everything you need to "attach" a file to your Rails model object, plus much much more.

Upvotes: 1

Related Questions