I'm having a headache with file upload in rails..
In short, the problem boils down to the upload form giving me a String
containing the file name of the uploaded file instead of the IO object
it should give me to access the file's content and MIME type.
I have checked http://railsforum.com/viewtopic.php?id=4642&p=1 and
http://manuals.rubyonrails.com/read/chapter/77, but the problem seems
not to occur there... I also have spent quite some time searching
google and this list on this issue, but nothing that succeeded to
enlighten me came up..
I'm using rails v. 1.2.1.
I have a view with a file upload form:
<% form_tag :action => 'create', :multipart => true do %>
<%= file_field('photo', 'uploaded_file') %>
<%= submit_tag "Create" %>
<% end %>
Which renders to
<form action="/photos/create?multipart=true" method="post">
<input id="photo_uploaded_file" name="photo[uploaded_file]"
size="30" type="file" />
<input name="commit" type="submit" value="Create" />
The database model has no column named 'uploaded_file' because this
value is to be split into a field for the MIME and one for the
content. So I added a setter method:
class Photo < ActiveRecord::Base
self.mime = file.content_type # => Raises undefined method
`content_type' for "Photo.jpg":String
The request parameters from rails' traceback are:
So also a string here...
Any help would be greatly appreciated!