Fw: [Rails] Re: attachment_fu content_type problem

Well,

It doesn’t look the my issue had to deal with the content_type at all.
Rather it was related to the size of the attachment. Seems that for
files < about 16k, Attachment_fu handles them as a StringObject. If
they exceed 16k they are stored as temp files which causes issues in
windows.

http://weblog.techno-weenie.net/2007/2/25/attachment_fu-tutorial

Since the files size stored in the database doesn’t matter to me I just
modified my model.

has_attachment :content_type => [‘application/pdf’,
‘application/msword’, ‘text/plain’],
:storage => :file_system,
:size => 0.byte…1.megabytes

If anybody knows of a better way to handle this, please let me know.

----- Original Message ----
From: “[email protected][email protected]
To: [email protected]
Sent: Monday, April 30, 2007 2:26:06 PM
Subject: [Rails] Re: attachment_fu content_type problem

I’m making some progress but I can’t figure out the error…

If I comment out this line in attachment_fu.rb my files upload but their
file size in the table is 0 (zero). If i uncomment the code the upload
fails with an invail field error. I have noticed that the code seems to
work on small files. <16k

validates the size and content_type attributes according to the

current model’s options
def attachment_attributes_valid?
[:size, :content_type].each do |attr_name|
enum = attachment_options[attr_name]

errors.add attr_name,

ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil?
|| enum.include?(send(attr_name))
end
end

This is what I’m doing to upload the files

Save the uploaded files

params[:documents].each do |doc|
@tournament.documents << Document.new(:uploaded_data => doc)
end unless params[:documents].nil?

----- Original Message ----
From: Mark [email protected]
To: Ruby on Rails: Talk [email protected]
Sent: Friday, April 27, 2007 5:58:21 PM
Subject: [Rails] attachment_fu content_type problem

Hi all…

Admittedly I’m new to Rails and trying to find my way but I’m having
an issue with uploading documents with attachment_fu.

I have a form where I’m uploading multiple attachments (using AJAX to
add file_filed_tags). That seems to work pretty well. The problem is
I can’t seem to get the content_type to work as I would expect. For
example, if I use this:

has_attachment :content_type => [‘application/pdf’, ‘application/
msword’, ‘text/plain’]

I would expect I can upload .pdf, .doc and .txt files but I get and
Document is invalid error (document is the name of my model) I have
played around with different content_types but I can’t seem to get
consistent results.

Thanks for any help.

  • Mark

Here is the document model

class Document < ActiveRecord::Base
belongs_to :tournament, :polymorphic => true

has_attachment :content_type => [‘application/pdf’, ‘application/
msword’, ‘text/plain’],
:storage => :file_system,
:max_size => 1.megabyte

validates_as_attachment

end