observer

Best way to send an email upon creation of a new model instance in Rails?

I have an app with the following models: User, Task, and Assignment. Each Assignment belongs_to a User and a Task (or in other words, a Task is assigned to a User via an Assignment). Once a User completes a Task, the Assignment is marked as complete, and the app immediately creates a new Assignment (or in other words, assigns the task t...

Why Observer pattern is much more complicated in C# than in Ruby?

I've read in "Design Patterns in Ruby" by Russ Olsen how Observer pattern can be implemented in Ruby. I've noticed that Ruby implementation of this pattern is much simpler than C# implementation, e.g. implementation shown in "Programming .NET 3.5" by Jesse Liberty and Alex Horovitz. So I've rewritten "Programming .NET 3.5" Observer ...

Observer design pattern in C++

Is the observer design pattern already defined in STL (Like the java.util.Observer and java.util.Observable in Java) ? ...

Keeping track of static method calls in a class using java.util.Observer

Hi, I'm a beginner programmer, and am wondering how to work around this issue. The problem I am trying to solve is keeping a tally of static method calls in my program using a java.util.Observer. Clearly, my original post must have just confused people so I'll leave it more open-ended: can anyone suggest a way to keep a static method ...

TypeError when trying to use observers and STI

I'm trying to follow along with the thread on implementing an achievement system (located at http://stackoverflow.com/questions/885277/how-to-implement-an-achievement-system-in-ror), and am running into a TypeError when the object is saved and the method awarded? gets called. The error looks like: TypeError (can't dump anonymous class C...

Ruby on Rails custom Observer

Could anyone advise how to use custom observer or events/callbacks in Ruby on Rails? I have tried both these posts: http://www.mutuallyhuman.com/2009/1/6/using-custom-activerecord-events-callbacks and http:// alexkira.blogspot.com/2008/10/custom-observer-callbacks-in-rails.html none seems to be working. On the second post, I put Alex ...

How to create a full Audit log in Rails for every table?

We recently began a compliance push at our company and are required to keep a full history of changes to our data which is currently managed in a Rails application. We've been given the OK to simply push something descriptive for every action to a log file, which is a fairly unobtrusive way to go. My inclination is to do something like...

'click' observer in Prototype

I have a page which contains several divs (each with a unique ID and the same class, 'parent'). Underneath each "parent" div, is a div with class "child" and unique ID name -child. This DIV is upon page load empty. Whenever you click on a parent DIV, the following code is executed. $$('div.parent').each(function(s){ $(s).observe('c...

Check / uncheck all checkboxes doesn't work in IE8

This javascript code does not work in IE8, but works in Firefox and Google Chrome: <% content_for :head do %> <script type="text/javascript"> document.observe("dom:loaded", function(){ // Observe toggler $('toggle_all').observe('change', function(){ var toggle = $('toggle_all').checked; $$('.check_boxes...

Rails Cache Sweeper and Model Callback Firing

Hey guys, I have the following classes: class Vigil < ActiveRecord::Base after_update :do_something_cool private def do_something_cool # Sweet code here end end class NewsFeedObserver < ActionController::Caching::Sweeper observe Vigil def after_update # Create a news feed entry end end Everything works ...

Where do I find good material on the Observer design pattern?

Where to find good material to study observer pattern? I need some examples, of code and also pictures of modelled situations ...

Adding Listeners at runtime? - Java MVC

My model in my MVC pattern, generates components at runtime and gives them to the View to be displayed on the screen through update() method (you know, model is the observable and the view is the observer). But I also need to add listeners to these components, and the controller has the listener methods (because they say the MVC pattern ...

How can I update information in an Android Activity from a background Service

Hello, I am trying to create a simple Android application that has a ActivityList of information, when the application starts, I plan to start a Service that will be constantly calculating the data (it will be changing) and I want the ActivityList to be in sync with the data that the service is calculating for the life of the app. How ...

Rosetta Stone: Observer Pattern

How is the Observer Pattern expressed in various programming languages? Can you provide a code snippet that illustrates the major differences in each language. This post is intended to demonstrate the differences of this commonly used design pattern. I will start this off with a Java example. Remember to start your answer off with the l...

Any recomendations for an efective way to sync data from one database, to other app's databases?

Here's my problem. I built a web app, and naturally kept the data in a database which describes that app's domain. Afterwords, I built another web app for the same organization, and used a seperate database to describe that app's domain and store data... and naturally a couple more projects came up and for each app I've isolated it's dat...

rails arguments to after_save observer

Hi, I want users to enter a comma-delimited list of logins on the form, to be notified by email when a new comment/post is created. I don't want to store this list in the database so I would use a form_tag_helper 'text_area_tag' instead of a form helper text_field. I have an 'after_save' observer which should send an email when the comm...

Can i create different observables and different corresponding observers in java?

Hello everyone, Currently, I have one observable and many observers. What i need is different observables, and depending on the observable, different observers. How do I achieve this? ( For understanding, assume I have different apples - say apple1 apple2... I have observer_1 observing apple1, observer_2 observing apple2, observer_3 obs...

How to handle data output in an Observer?

I have an Observable and an Observer. The observable does download some stuff in a background thread and calls notifyObservers to let the observers read the status. At some point in public void update the observer tries to updates the GUI ((TextView)findViewById('R.id.foo')).setText("bar"); but it seems like the observable thread ca...

My Active Record Observer is not called

i made one observer named inquiry for send notification email my model name is also inquiry but its not called i cant understand what is the problem i also made configuration in environment.rb file like this config.active_record.observers = :inquiry_observer ...

Handling exceptions raised in observers

I have a Rails (2.3.5) application where there are many groups, and each Group has_many People. I have a Group edit form where users can create new people. When a new person is created, they are sent an email (the email address is user entered on the form). This is accomplished with an observer on the Person model. The problem comes...