How can I send a welcome email to newly registered users in Rails using Devise?

552 views
Skip to first unread message

Volkan Unsal

unread,
Nov 9, 2010, 8:49:49 PM11/9/10
to Devise
I am using Devise on Rails and I'm wondering if there is a hook or a
filter that I can use to add a bit of code to Devise's user
registration process and send a welcome email to the user after an
account has been created.

Nicholas Young

unread,
Nov 9, 2010, 9:38:09 PM11/9/10
to plataforma...@googlegroups.com
I believe this has been discussed on the list several times. Just do a search, and you should find a solution.

Nicholas

Sent from my iPhone

Volkan Unsal

unread,
Nov 9, 2010, 9:59:15 PM11/9/10
to Devise
I'm using Mongoid, though. ActiveRecord::Observer is throwing an error
for me.



On Nov 9, 9:38 pm, Nicholas Young <nicho...@nicholaswyoung.com> wrote:
> I believe this has been discussed on the list several times. Just do a search, and you should find a solution.  
>
> Nicholas
>
> Sent from my iPhone
>

Volkan Unsal

unread,
Nov 9, 2010, 10:06:23 PM11/9/10
to Devise
It would be great if there were a non-ActiveRecord dependent way of
hooking into the registration process.

Alex Grebennik

unread,
Nov 9, 2010, 10:07:59 PM11/9/10
to plataforma...@googlegroups.com
i dont think that there is problem in devise, but if you can provide sample app (on github) it will be great.

Volkan Unsal

unread,
Nov 9, 2010, 10:19:47 PM11/9/10
to Devise
Sorry, I didn't mean to imply that. I think I found another way,
though.

class User
include Mongoid::Document
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

after_create :send_activation_mail
def send_activation_mail
Contact.welcome_email.deliver
end
...

end

This appears to be working as far as I can tell.

Volkan Unsal

unread,
Nov 9, 2010, 10:28:18 PM11/9/10
to Devise
I wonder if you know how I can get a reference to the newly created
user class from inside the class? i tried self

Contact.welcome_email(self).deliver

Also..thanks for all your help so far. :-)



On Nov 9, 10:07 pm, Alex Grebennik <aleks.greben...@gmail.com> wrote:

Carlos Antonio da Silva

unread,
Nov 11, 2010, 9:10:15 AM11/11/10
to plataforma...@googlegroups.com
To the class? Isn't that User?
self is the current user in your case. self.class would return the User class.
--
At.
Carlos A. da Silva
Reply all
Reply to author
Forward
0 new messages