Ruby on Rails

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsWeb Design & DevelopmentRuby on Rails

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old October 27th, 2010, 01:48 PM
bchin bchin is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Posts: 2 bchin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 20 sec
Reputation Power: 0
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
Code:
(bchin ~/setup/rails/pratice/app/models)cat foo.rb 
class Foo < ActiveRecord::Base
end

and my foo_observer.rb
Code:
(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
Code:
(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
Code:
(bchin ~/setup/rails/pratice/script)./console 
Loading development environment (Rails 2.3.2)
>> Foo.create
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.

Reply With Quote
  #2  
Old October 29th, 2010, 05:41 PM
bchin bchin is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Posts: 2 bchin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 20 sec
Reputation Power: 0
well, looks like I can just following this guide, http://guides.rubyonrails.org/testing.html to get my automated testing done. So I followed the guides and re-created all my objects using 'rails generate', but now I'm getting the following error:
Code:
(bchin ~/setup/rails/practice)rails console
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/application.rb:63:in `inherited': You cannot have more than one Rails::Application (RuntimeError)
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/deprecation.rb:7:in `initialize'
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/deprecation.rb:7:in `new'
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/deprecation.rb:7:in `run'
	from /home/bchin/setup/rails/ioffer_cl/config/environment.rb:7:in `<top (required)>'
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/application.rb:103:in `require'
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/application.rb:103:in `require_environment!'
	from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:22:in `<top (required)>'
	from script/rails:6:in `require'
	from script/rails:6:in `<main>'


What does this error mean?

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentRuby on Rails > Trouble with Callbacks


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap