Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Trouble with Callbacks
1 Post
Trouble with Callbacks

Hi,

I'm still new to Ruby on Rails, and I want to utilize ActiveRecord::Observer. I got Observer working under the rails environment by putting my rb files under app/model and configuring config/environment.rb. However, I want to automate the testing of my site via command line. Is this possible?

So, I have a foo.rb

(bchin ~/setup/rails/pratice/app/models)cat foo.rb class Foo < ActiveRecord::Base end

and my foo_observer.rb

(bchin ~/setup/rails/pratice/app/models)cat foo_observer.rb class FooObserver < ActiveRecord::Observer

def after_create(foo)

puts foo.id
Foo.find(foo.id)

end

end

and I registered foo_observer under config/environment

(bchin ~/setup/rails/pratice/app/models)grep 'foo' ../../config/environment.rb config.active_record.observers = :foo_observer

And, when I go to the console, everything works as expected

(bchin ~/setup/rails/pratice/script)./console Loading development environment (Rails 2.3.2)

Foo.create 2 => #

How can I use ruby to test this? I tried creating a main.rb, which 'require' foo and foo_observer, but that doesn't seem to work. What am I missing? Thanks for any help anyone can provide.

1 Post
Login to add your message