# Re: attachment\_fu content\_type problem

**URL:** <https://www.ruby-forum.com/t/re-attachment-fu-content-type-problem/103014>\
**Category:** Rails\
**Created:** [April 30, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/re-attachment-fu-content-type-problem/103014 "2007-04-30T20:27:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mslagell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mslagell](https://www.ruby-forum.com/u/mslagell)\
**Post date:** [April 30, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/re-attachment-fu-content-type-problem/103014/1 "2007-04-30T20:27:21Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: Ruby on Rails: Talk [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
