similar to: Minimum needed to observe a model

Displaying 20 results from an estimated 10000 matches similar to: "Minimum needed to observe a model"

2006 Apr 26
1
Observer best practices
I''ve seen two ways of connecting observers: 1) In the observer class put observe MyModel 2) In the controller class put observer :my_observer What is the difference between these two? Also, is it necessary to put in the observer class the following? MyObserver.instance Jose -- Posted via http://www.ruby-forum.com/.
2011 Dec 02
2
problem setting expectation for test with delayed::job
I''ve got something like this: # post_observer.rb after_create # ...stuff Delayed::Job.enqueue(PostSharer.new(post, post.user)) end ... # post_sharer.rb class PostSharer < Struct.new(:post, user) def perform # Delayed::Job calls .perform on the object passed into enqueue end end # post_controller_spec.rb it "shares the post" do
2006 Mar 04
2
Declaring ActiveRecord observers
Hello I''m using the ''act_as_authenticated'' plugin to implement a small and simple authentication system in my app. Everything is working just fine and the world is a better place to live in. The plugin creates a ActiveRecord observer in order to send the newly registered user a confirmation e-mail. Per the API docs [1], one should declare the observer in the
2006 May 24
1
Observer behavior differences between DEV and TEST environments ?
Hi all ! I''m having an issue and I can''t seem to make heads or tails of it. I am attempting to add an observer to a model object. I created app/models/greenback_transaction_observer.rb, inherited from AR::Observer, defined methods, registered in config/environment.rb, but things don''t work... So, I took a step back and put in the following code: class
2008 Jan 12
0
Can't test application controller methods in functional tests?
I have two methods in application controller that I want to test from ForumController: ----------------------- class ApplicationController < ActionController::Base ... def logout session[:username] = nil session[:admin] = nil redirect_to(request.request_uri) end ... def home redirect_to(:controller => ''forum'', :action =>
2006 Aug 16
1
Active Record Observers causing 404''s and other weird issues
Hi all. I''ve got a simple AR Observer: class NewOrderObserver < ActiveRecord::Observer observe NewOrder def after_create(object) Note.create(...) end end In environment.rb I have the following line: config.active_record.observers = :new_order_observer And in application.rb I have: NewOrderObserver.instance Aside from simply not working, it''s causing
2008 Feb 05
0
adding observers outside environment.rb
I need to add an ActiveRecord observer and thought I should follow Rails 2 intent by not changing the base environment.rb I create a file config/initializers/observers.rb but don''t know what to add to it. I can''t add: config.active_record.observers = :user_observer Since "config" isn''t defined in the scope of the initializer file and I don''t know if
2007 Jan 22
1
Observed models cause failures with DRBSpec ?
Hi all ! I don''t believe I am the only one using model observers, right ? Well, here''s a nice one: $ drbspec spec . Finished in 0.125322 seconds 1 specification, 0 failures $ drbspec spec F 1) ''A user with an inactive and an active project should be able to return active projects only'' FAILED [] should == [#<Spec::Mocks::Mock:0xb75590bc
2006 Feb 19
0
newbe: observer setup
Hi All, Having problem setting up an observer to log changes to a database. I have following the Prag Rails book but think I have something missing. I am trying a simple puts to see if the observer is working, but getting nothing on the console. Here is what I have. I don''t get any errors. Thanks for any suggestions/references to debugging. Dave The two models: display_ad.rd
2006 Feb 22
0
How to get model observer to work?
I can''t seem to get a model observer to work. In my environment.rb I have: config.active_record.observers = :item_observer In item_observer.rb I have: class ItemObserver < ActiveRecord::Observer observe Item def after_update(item) if @old.active != item.active logger.debug ''observer#after_update'' #... end @old = nil end def
2010 Oct 03
1
Rails 3 observers
Rails Guides says: ...the UserObserver ... would be saved as app/models/user_observer.rb and registered in config/environment.rb this way: config.active_record.observers = :user_observer But the observer registration above doesn''t work because there is no ''config''. For now, I''ve put it in the config/environments/[APP_ENV].rb but that seems really sloppy and
2006 Jul 18
7
Observer not working
Help please. I''m trying to observe a User class, but I can''t get this to work, the after_create method never gets called... (the breakpoint never gets called) app/models/user_observer.rb: class UserObserver < ActiveRecord::Observer def after_create(user) breakpoint setting =
2010 Mar 09
1
db:migrate fails after upgrade to Rails 2.3.5
Hi -- I''m upgrading an app from Rails 2.0.2 to 2.3.5 in development on a Mac OS/X Leopard. I unfroze the old Rails files, froze the 2.3.5 gem on the machine into the app, and some quick tests of the app showed no problems. However, after trying to run rake db:migrate, it fails silently. Run with trace I get the output below. I gather it might be related to plugin initialization or
2008 May 16
3
radio button observe field only triggers once
Hi, If i add field observers to radio button fields they trigger once but then nothing after that. I have multiple fields in a form that i need to know if one of them changes and which spedific field. Below is an example of two foelds i tested and they trigger once with the alert but then nothing after that. I also tried individual observers for each field test_yes and test_no but with the same
2006 May 03
0
Testing Observers
Greetings all, As a Noob, I''ve been diligently working my way through the AWD4R book and finally arrived at the part about observers -- which BTW I think are very cool tech. Anyhow, I got the Audit Observer working. Now I want to test it and perhaps examine it''s attributes and methods to make sure it does what is expected of it. For example, one thing I would like to do
2006 Mar 10
9
Observers?
Hello all! I''m having an issue with Observers, and I''m hoping someone knows the answer. Here is the definition: app/models/vehicle_observer.rb > class VehicleObserver < ActiveRecord::Observer > def after_save(vehicle) > breakpoint > if vehicle.has_new_mil_indication? > UserMailer.deliver_mil_notice(vehicle) > end > end > end
2006 Nov 04
0
ActiveRecord Observers and Model breakage.
I''m attempting to assign ActiveRecord Observers to some of my models, specified in config/environment.rb like so, config.active_record.observers = :presentation_observer, :asset_observer, :tag_observer My models use plugins which extend ActiveRecord::Base, including Sebastian Kanthak''s file_column Attempting to boot mongrel yields:
2006 Feb 22
2
Removing form observers
Hi, I''m developing a Rails app which uses dynamic forms. To implement these, I''ve used AJAX and Rails''s built-in form observers. Unfortunately, I''m having a problem. This is how the form starts: * Country select box [OBSERVED] (Republic of Ireland selected) * County select box [OBSERVED] (none selected, list of Republic of Irish counties in the drop down)
2010 Apr 16
1
Active Record observers broken: can't be used for "before" callbacks
I was just wondering what about a report that I made almost 2 months ago: Active Record observers broken<https://rails.lighthouseapp.com/projects/8994/tickets/4087-activerecord-observers-cant-be-used-for-before-callbacks> I think it''s a pretty big bug. In Rails 3, creating an observer with a "before_save" callback (for instance) will result in all observed models being
2007 Jan 18
1
spec''ing models with observers that send mail
I''m spec''ing a model with an observer that sends mail. Mailers behave similarly to controllers, so to make the whole thing work, I believe something like integrate_views has to be available. Has anyone dealt with observers and ActionMailer? Thanks