Настроить Devise для Mailchimp
Новичок в Rails, и я подключаюсь к Mailchimp API через Gibbon.
Я хотел добавить подписчиков своего приложения в список рассылки без необходимости подписывать подтверждение дважды. Поэтому я добавил вызов API для Mailchimp, когда новый пользователь создается внутри Devise::RegistrationsController. Тем не менее, я думаю, что он должен быть добавлен после подтверждения по электронной почте. Но я не вижу, где это сделать правильно внутри Devise::RegistrationsController. Вот мой существующий код... спасибо.
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
if resource.save
# Add the new user email to Mailchimp
# double-optin is part of the Mailchimp API that sends/doesn't send a confirmation email
# in this case I'm already sending a confirm signup email
# which already informs them they'll be added to a mailing list
gb = Gibbon.new('my-mailchimp-api')
gb.list_subscribe({:id => 'my-mailchimp-list-id',
:email_address => resource.email,
:merge_vars => {:FNAME => resource.forename, :LNAME => resource.surname },
:double_optin => "false"})
end
end
def edit
super
end
def update
super
end
def destroy
super
end
def cancel
super
end
protected
def update_needs_confirmation?(resource, previous)
super
end
def build_resource(hash=nil)
super
end
def sign_up(resource_name, resource)
super
end
def after_sign_up_path_for(resource)
super
end
def after_inactive_sign_up_path_for(resource)
super
end
def after_update_path_for(resource)
super
end
def authenticate_scope!
super
end
def sign_up_params
super
end
def account_update_params
super
end
end
2 ответа
Это довольно легко достичь, вы можете сделать это, переопределив confirm!
метод в вашей пользовательской модели:
def confirm!
super
do_some_mailchimp_stuff
end
Надеюсь это поможет!
Вы можете использовать гем devise_mailchimp. Это доступно здесь https://github.com/jcnnghm/devise_mailchimp