I’ve searched in vain for a basic tutorial on how to upload a binary
file to a database using vanilla Rails 3. Yes, I know about Paperclip;
no, I don’t want to upload the files to a filesystem.
What I’d really like to do is capture the filename, mime-type, and
data inside the create/update action–no separate upload action
required, as the table is dedicated to the file uploads.
So far, I have this:
= form_for @photo, :html => { :multipart => true } do |f|
= f.label :data
%br/
= f.file_field :data
.actions
= f.submit
but get festive error messages like:
NoMethodError in PhotosController#create
undefined method `gsub’ for #<ActionDispatch::Http::UploadedFile:
0xa64da84>
when I submit the form. What should my create/update actions look like
in order to store the file and metadata properly inside the database?