Using ActiveRecord, is there a way to get the old values of a record during after_update

Ditto what everyone is saying about transactions. That said… ActiveRecord as of Rails 2.1 keeps track of the attribute values of an object. So if you have an attribute total, you will have a total_changed? method and a total_was method that returns the old value. There’s no need to add anything to your model to … Read more

How can I pass a class member function as a callback?

This is a simple question but the answer is surprisingly complex. The short answer is you can do what you’re trying to do with std::bind1st or boost::bind. The longer answer is below. The compiler is correct to suggest you use &CLoggersInfra::RedundencyManagerCallBack. First, if RedundencyManagerCallBack is a member function, the function itself doesn’t belong to any … Read more

Why is my Button’s command executed immediately when I create the Button, and not when I click it? [duplicate]

Consider this code: b = Button(admin, text=”as”, command=button(‘hey’)) It does exactly the same as this: result = button(‘hey’) b = button(admin, text=”as”, command=result) Likewise, if you create a binding like this: listbox.bind(“<<ListboxSelect>>”, some_function()) … it’s the same as this: result = some_function() listbox.bind(“<<ListboxSelect>>”, result) The command option takes a reference to a function, which is … Read more

C++ callback using class member

Instead of having static methods and passing around a pointer to the class instance, you could use functionality in the new C++11 standard: std::function and std::bind: #include <functional> class EventHandler { public: void addHandler(std::function<void(int)> callback) { cout << “Handler added…” << endl; // Let’s pretend an event just occured callback(1); } }; The addHandler method … Read more

back button callback in navigationController in iOS

William Jockusch’s answer solve this problem with easy trick. -(void) viewWillDisappear:(BOOL)animated { if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) { // back button was pressed. We know this is true because self is no longer // in the navigation stack. } [super viewWillDisappear:animated]; }

nodejs – first argument must be a string or Buffer – when using response.write with http.request

I get this error message and it mentions options.body I had this originally request.post({ url: apiServerBaseUrl + ‘/v1/verify’, body: { email: req.user.email } }); I changed it to this: request.post({ url: apiServerBaseUrl + ‘/v1/verify’, body: JSON.stringify({ email: req.user.email }) }); and it seems to work now without the error message…seems like bug though. I think … Read more

Using PassportJS, how does one pass additional form fields to the local authentication strategy?

There’s a passReqToCallback option that you can enable, like so: passport.use(new LocalStrategy( {usernameField: ’email’, passReqToCallback: true}, function(req, email, password, done) { // now you can check req.body.foo } )); When, set req becomes the first argument to the verify callback, and you can inspect it as you wish.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)