Trouble with Callbacks


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

and my foo_observer.rb

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

def after_create(foo)


and I registered foo_observer under config/environment

(bchin ~/setup/rails/pratice/app/models)grep ‘foo’
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 id: 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs