# Nil Object

**URL:** <https://www.ruby-forum.com/t/nil-object/138833>\
**Category:** Rails\
**Created:** [May 28, 2008, 6:09am UTC](https://www.ruby-forum.com/t/nil-object/138833 "2008-05-28T06:09:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wawa88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@wawa88](https://www.ruby-forum.com/u/wawa88)\
**Post date:** [May 28, 2008, 6:09am UTC](https://www.ruby-forum.com/t/nil-object/138833/1 "2008-05-28T06:09:39Z")

</div>

Hi everyone I’m new to ROR. I am receiving email using ActionMailer. I  
need some help about the error nil object i got. Anyway i am doing rails  
on window platform.

At first I generate the code  
ruby script/generate migration CreateTables to generate the file below.

db/migrate/001\_create\_tables.rb:  
class CreateTables \< ActiveRecord::Migration  
def self.up  
create\_table(:pages) do |t|  
t.column :address, :string  
end  
create\_table(:emails) do |t|  
t.column :page\_id, :integer  
t.column :subject, :string  
t.column :body, :string  
end  
create\_table(:attachments) do |t|  
t.column :page\_id, :integer  
t.column :file, :binary  
t.column :description, :string  
end  
end

def self.down  
drop\_table :attachments  
drop\_table :emails  
drop\_table :pages  
end  
end

Then in model i got a EventMailer:

class EventMailer \< ActionMailer::Base  
def receive(email)  
page = page.find\_by\_address(email.to.first)  
page.emails.create(  
:subject =\> email.subject,  
:body =\> email.body  
)

```
  if email.has_attachments?
    for attachment in email.attachments
      page.attachments.create({
        :file => attachment,
        :description => email.subject
      })
    end
  end

```

end

end

Then i do these  
ruby script/generate model Page  
ruby script/generate model Email  
ruby script/generate model Attachment

After that i rake db:migrate

Then i got a page.rb in the model:  
class Page \< ActiveRecord::Base  
has\_many :emails  
has\_many :attachments  
end

When i run ruby script/runner EventMailer.receive(STDIN.read) \<  
ForActionMailer.txt

\*Note: ForActionMailer.txt is a text file contains the email i fetched  
from gmail by using fetch\_mail.

But i got an nil object error.

Please help. Thanks

Wawa
