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