I’ve been trying to do simple file uploads but I am unable to find a gem that does it, all of them just seem to be orientated around
images. I just want basic .zip file uploads. Could someone instruct me to a gem that does this or a tutorial that builds your own custom
uploads. However, if there are none, I’ll create my own file uploading, but then I am faced with the following question
The question:
How do I store the file’s path in the database when the user hits the upload button?
Below is the scenario:
The form consists of the following:
Title box:
File select box:
Upload button:
The database table just consists of two columns, the title (Title) and the file's path (FilePath) on the filesystem
The user fills in the title, browses for the file on their system, and clicks on the upload button, the file then needs
to be stored on the disk, lets say /public/uploads/file1.zip while also writing to the mysql database the Title of the upload as well as
the path to the actual file that resides now in /public/uploads/file1.zip.
On another page, I can simply just query the database to retrieve the Title and FilePath which will display the Title and a link/path to the file that a user can simply just click on and download.
It will be displayed on the page as follows:
Title – Download
so i.e Conference Document for the 27th – Download
Where “Title” = user submitted file title and “Download” = the actual link you can click on that will retrieve the file from the disk
and start downloading. This needs to be one query from the database that retrieves the title and the path to the file. The querying
part I know how to do. It’s just the part of uploading the file to that directory, storing the directory for that specific file in the database and it’s Title the user submitted.
Any suggestions, examples and resources will be greatly appreciated. Thanks for your time.
Read uploading files from the rails guides and then read the CarrierWave README. Basically it’s:
The filesystem path will be stored in the table column you mount on.