# Can't dump anonymous class Class

**URL:** <https://www.ruby-forum.com/t/cant-dump-anonymous-class-class/63864>\
**Category:** Rails\
**Created:** [June 20, 2006, 12:00am UTC](https://www.ruby-forum.com/t/cant-dump-anonymous-class-class/63864 "2006-06-20T00:00:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gers4302](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c2a13f/32.png) [@gers4302](https://www.ruby-forum.com/u/gers4302)\
**Post date:** [June 20, 2006, 12:00am UTC](https://www.ruby-forum.com/t/cant-dump-anonymous-class-class/63864/1 "2006-06-20T00:00:07Z")

</div>

I’m trying to create a document upload system, where most of the code is  
the super class Document and just the path to file on the system is  
controlled by the sub classes. When I attempt to use my code, I get the  
following when I try to save the document.

can’t dump anonymous class Class

Any ideas?

\*\* Migration \*\*

class CreateDocuments \< ActiveRecord::Migration

def self.up  
create\_table :documents do |t|  
t.column :type, :string  
t.column :name, :string  
t.column :file\_path, :string  
t.column :content\_type, :string  
t.column :created\_on, :timestamp  
# attributes for type=“AssociationDocument”  
t.column :association\_id, :integer  
# attributes for type=“LocationDocument”  
t.column :location\_id, :integer  
end  
end

def self.down  
drop\_table :documents  
end

end

\*\* Models \*\*  
class Document \< ActiveRecord::Base

attr\_accessor :uploaded\_file

def after\_create  
if !File.exists?(File.dirname(self.file\_path))  
Dir.mkdir(File.dirname(self.file\_path))  
end

```
if @uploaded_file.instance_of?(Tempfile)
  FileUtils.copy(@uploaded_file.local_path, self.file_path)
else
  File.open(self.file_path, "wb") { |f| f.write(@uploaded_file.read) 

```

}  
end  
end

def after\_destroy  
if File.exists?(self.file\_path)  
File.delete(self.file\_path)  
end  
end

def file=(uploaded\_file)  
@uploaded\_file = uploaded\_file  
self.file\_path = sanitize\_filename(@uploaded\_file.original\_filename)  
self.content\_type = @uploaded\_file.content\_type  
end

private  
def new\_filename(file\_name)  
idx = file\_name.rindex “.”  
self.name.gsub(/[^\w.\_]/, ‘\_’) + file\_name[idx, file\_name.length -  
idx]  
end

def sanitize\_filename(file\_name)  
File.expand\_path("#{RAILS\_ROOT}/public/documents/#{new\_filename(file\_name)}")  
end

end

class GlobalDocument \< Document

validates\_uniqueness\_of :name, :scope =\> :type

private  
def sanitize\_filename(file\_name)  
File.expand\_path("#{RAILS\_ROOT}/public/documents/global/#{new\_filename(file\_name)}")  
end

end

\*\* Controller \*\*

def documents  
@associations = Association.find(:all, :order =\> [“name”])  
@association\_documents = AssociationDocument.find(:all, :include =\>  
[“association”])  
@global\_documents = GlobalDocument.find\_all()  
@new\_document = GlobalDocument.new  
end

def save\_global\_document  
doc = GlobalDocument.new(params[:new\_document])  
if doc.save  
flash[:notice] = “_#{doc.name}_ was saved”  
else  
flash[:error] = doc.errors.full\_messages.join("  
")  
end  
redirect\_to :action =\> :documents  
end

\*\* View \*\*  
documents.rhtml

```
<%= form_tag({ :action => :save_global_document }, { :multipart => 

```

true }) %\>

  
  
  
  
  
  
  
  
  
  
  
  
  

| Name: | \<%= text\_field :new\_document, :name, :class =\> “fixed”  
%\> |
| File: | \<%= file\_field :new\_document, :file, :class =\> “fixed”  
%\> |
| | \<%= submit\_tag “Upload file” %\> |

  
\<%= end\_form\_tag %\>

---

<div class="post-metadata">

**Author:** ![gers4302](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c2a13f/32.png) [@gers4302](https://www.ruby-forum.com/u/gers4302)\
**Post date:** [June 20, 2006, 12:29am UTC](https://www.ruby-forum.com/t/cant-dump-anonymous-class-class/63864/2 "2006-06-20T00:29:37Z")

</div>

On 6/19/06, Stephen G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to create a document upload system, where most of the code is  
> the super class Document and just the path to file on the system is  
> controlled by the sub classes. When I attempt to use my code, I get the  
> following when I try to save the document.
> 
> can’t dump anonymous class Class
> 
> Any ideas?

Do you have a stack trace from your logs that shows which line of code  
is causing this?

– James
