I'm using restful_authentication in my app. I'm creating a set of default users using a rake task, but every time I run the task an activation email is sent out because of the observer associated with my user model. I'm setting the activation fields when I create the users, so no activation is necessary.
Anyone know of an easy way to bypass observers while running a rake task so that no emails get sent out when I save the user?
Thanks.
In generally, for these sorts of situations, you can:
In this case, I'd say #3 is your best bet.
I came here looking for the an answer to the same... none of the above seemed to do the trick (or involve adding migration-specific logic to my application code -- boo).
Here's what I came up with (a bit lame that it needs to go in each relevant migration, but...)
Rails 3.1 finally comes with API for this: http://api.rubyonrails.org/v3.1.0/classes/ActiveModel/ObserverArray.html#method-i-disable
Where
ORM
could for example beActiveRecord::Base
When running tests on an app I am working on, I use the following:
You could add an accessor to your user model, something like "skip_activation" that wouldn't need to be saved, but would persist through the session, and then check the flag in the observer. Something like
Then, in the observer:
As others have hinted; I would wrap the unwanted logic in your Observer with a simple if statement.