W dniu 2011-03-22 03:22, Todd A. Jacobs pisze:
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?

My basic version is
# view
<%= form_for @photo, :html => {:multipart => true } do |f| %>
<%= f.file_field :upload %>
<%= f.submit "Save" %>
<% end %>

# controller
    ...
    @photo.save
    ...

# model
   attr_accessor :upload


--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to