Rails的新手,我正在通过Gibbon连接到Mailchimp API。
我想将我的应用的订阅者添加到邮件列表中,而不必签署确认两次。所以当在Devise :: RegistrationsController中创建一个新用户时,我已经向Mailchimp添加了API调用。但是,我猜它应该在确认电子邮件中确认之后才能添加。但我无法在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
答案 0 :(得分:1)
这很容易实现,您可以通过覆盖用户模型中的confirm!
方法来实现:
def confirm!
super
do_some_mailchimp_stuff
end
希望这有帮助!
答案 1 :(得分:0)
您可以使用 devise_mailchimp gem。它可以在这里https://github.com/jcnnghm/devise_mailchimp