Forum: Ruby on Rails Re: attachment_fu content_type problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4c2e3a5381459411d3ba43e7383505ed?d=identicon&s=25 Mark Studebaker (mstudebaker)
on 2007-04-30 20:27
(Received via mailing list)
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))

This is what I'm doing to upload the files

# Save the uploaded files
params[:documents].each do |doc|
@tournament.documents << => doc)
end unless params[:documents].nil?

----- Original Message ----
From: Mark <>
To: Ruby on Rails: Talk <>
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


This topic is locked and can not be replied to.