1

Rails 新手,我正在通过 Gibbon 连接到 Mailchimp API。

我想将我的应用程序的订阅者添加到邮件列表中,而无需他们签署两次确认。因此,当在 Devise::RegistrationsController 中创建新用户时,我已将 API 调用添加到 Mailchimp。但是,我想一旦他们从确认电子邮件中确认,它实际上应该被添加。但我看不到在 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
4

2 回答 2

1

这很容易实现,您可以通过覆盖confirm!用户模型中的方法来实现:

def confirm!
  super
  do_some_mailchimp_stuff
end

希望这可以帮助!

于 2013-10-04T00:24:35.260 回答
0

您可以使用devise_mailchimp gem。它可以在这里https://github.com/jcnnghm/devise_mailchimp

于 2014-09-12T11:22:45.213 回答