Rails after_create callback can't access model's attributes?

Try this instead: class Dog Gender} user:#{dog. User_id}" end end.

This is how I'm doing it in my observers. – Jimmy Baker Apr 7 '10 at 17:05 how do you pass a variable to after_create? – tybro0103 Apr 7 '10 at 18:04.

The macro style callback is probably a better idea generally than simply overriding the method. It lets you fire a few different methods at the same time in the lifecycle (if you want). I think what you need is this: class Dog Debug "DOG CREATED color:#{self.

Color} gender:#{self. Gender} user:#{self. User_id}" end end.

Yeah, I like this method too, but it wouldn't affect my problem. – tybro0103 Apr 9 '10 at 14:51.

Figured out my own problem. One of the attributes was a virtual one, in which I used self. Update_attribute...oops!

Def price=(amt) self. Update_attribute(:price_in_cents, (amt*100.0). To_i) end So for the record, update_attribute will actually create database record (and trigger after_create) if it hasn't been created yet.

Next time I'll be sure to post full code!

Try using after_save instead of after_create may be that works. No tested though. After_create () Is called after Base.

Save on new objects that haven‘t been saved yet (no record exists). Note that this callback is still wrapped in the transaction around save. For example, if you invoke an external indexer at this point it won‘t see the changes in the database.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions