Coder Social home page Coder Social logo

devise_mailchimp's Introduction

Devise MailChimp

Devise MailChimp adds a MailChimp option to devise that easily enables users to join your mailing list when they create an account.

Delayed Job is used automatically if your project uses it, and the mapping between list names and list ids is cached automatically.

Getting started

In your Gemfile, add devise_mailchimp after devise:

gem "devise"
gem "devise_mailchimp"  # Last officially released gem

In your User model, add :mailchimp to the devise call and make :join_mailing_list accessible:

devise :database_authenticatable, ..., :mailchimp
attr_accessible :join_mailing_list

In your devise initializer (config/initializers/devise.rb), set your API key and mailing list name:

Devise.mailchimp_api_key = 'your_api_key'
Devise.mailing_list_name = 'List Name'
Devise.double_opt_in = false  
Devise.send_welcome_email = false

If you are using the default Devise registration views, the Join Mailing List checkbox is added automatically, if not, either include the form partial in your new registration form:

<%= render :partial => "devise/shared/mailchimp/form", :locals => {:form => f} %>

Or manually add a “Join Mailing List” checkbox to your new registration form:

<%= form.check_box :join_mailing_list %>

If you are using Simple Form, you can use:

<%= f.input :join_mailing_list, :as => :boolean %>

Configuration

Create an initializer, and set your MailChimp API key. To generate a new API key, go to the account tab in your MailChimp account and select API Keys & Authorized Apps, then add a key.

Devise.mailchimp_api_key = 'your_api_key'

Create a mailing list, and set the mailing list name in the initializer. To create a MailChimp list, from your account go to the Lists tab, then hit create list.

Devise.mailing_list_name = 'List Name'

Add options from the MailChimp API Docs using the following code in user.rb model. For GROUPINGS, you can get the Group ID by clicking “import to” and looking at the URL us6.admin.mailchimp.com/lists/members/import?id=1234&grp=9999&int=1

def mailchimp_list_subscribe_options
  {'FNAME' => self.first_name, 'LNAME' => self.last_name, 'GROUPINGS'=> { 0 => {'id' => 9999, 'groups' => "Signed Up" } } }
end

For all the configuration settings, take a look at the model documenation.

Documentation

Full documentation is available at rdoc.info.

Demo Application

A demo application is available at github.

Example Usage

Users will join the default mailing list if join_mailing_list is set to true when the user is created. To manually add a user:

User.find(1).add_to_mailchimp_list('Site Administrators List')

To manually remove a user:

User.find(1).remove_from_mailchimp_list('Site Administrators List')

NOTE: You MUST have the users permission to add them to a mailing list.

Customization

To have the user join more than one list, or to override the lists that the user will join, override mailchimp_lists_to_join in your model. Your method should return a single list, or an array of lists.

def mailchimp_lists_to_join
  lists = ["Site Users List"]
  lists << "Site Admins List" if admin?
  return lists
end

If all users will join the same list or lists, just set the mailing_list_name configuration option.

Contributions

Please help this software improve by submitting pull requests, preferably with tests.

View our contributors.

Copyright © 2011 Justin Cunningham. See MIT_LICENSE for details.

devise_mailchimp's People

Contributors

bcleenders avatar justincinmd avatar naoisegolden avatar stefanwille avatar stemps avatar teamon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

devise_mailchimp's Issues

Wrong size

I see this gem uses the hominid gem, which fails with ruby 2.0.0

https://github.com/tatemae-consultancy/hominid/issues/55

is there a way to fix this?

trace:

Wrong size. Was 5714, should be 760
/usr/local/rbenv/versions/2.0.0-rc2/lib/ruby/2.0.0/xmlrpc/client.rb:506:in `do_rpc'
/usr/local/rbenv/versions/2.0.0-rc2/lib/ruby/2.0.0/xmlrpc/client.rb:281:in `call2'
/usr/local/rbenv/versions/2.0.0-rc2/lib/ruby/2.0.0/xmlrpc/client.rb:262:in `call'
/home/naviprofi/apps/naviprofi/shared/bundle/ruby/2.0.0/gems/hominid-3.0.5/lib/hominid/api.rb:32:in `method_missing'
/home/naviprofi/apps/naviprofi/shared/bundle/ruby/2.0.0/gems/hominid-3.0.5/lib/hominid/list.rb:6:in `find_list_by_name'
/home/naviprofi/apps/naviprofi/shared/bundle/ruby/2.0.0/gems/hominid-3.0.5/lib/hominid/list.rb:11:in `find_list_id_by_name'
/home/naviprofi/apps/naviprofi/shared/bundle/ruby/2.0.0/gems/devise_mailchimp-0.0.4/lib/devise_mailchimp/mailchimp_list_api_mapper.rb:21:in `name_to_id'
/home/naviprofi/apps/naviprofi/shared/bundle/ruby/2.0.0/gems/devise_mailchimp-0.0.4/lib/devise_mailchimp/mailchimp_list_api_mapper.rb:39:in `block in subscribe_to_lists'
/home/naviprofi/apps/naviprofi/shared/bundle/ruby/2.0.0/gems/devise_mailchimp-0.0.4/lib/devise_mailchimp/mailchimp_list_api_mapper.rb:38:in `each'
/home/naviprofi/apps/naviprofi/shared/bundle/ruby/2.0.0/gems/devise_mailchimp-0.0.4/lib/devise_mailchimp/mailchimp_list_api_mapper.rb:38:in `subscribe_to_lists'

Couldn't Install

Gemfile:

gem 'devise'
gem 'devise_invitable', '~> 1.0.0'
gem 'devise_mailchimp'

Error from 'bundle install':

Bundler could not find compatible versions for gem "devise":
  In Gemfile:
    devise_mailchimp (>= 0) ruby depends on
      devise (~> 1.4.8) ruby

    devise_invitable (~> 1.0.0) ruby depends on
      devise (2.2.2)

test sendmail with rspec

hi everyone, how could config to test send mail by rspec in enviroments: test, development, production?

config.mailing_list_opt_in_by_default = true is not working

When I remove <%= f.input_field :join_mailing_list, :as => :boolean %> from my registration form and add config.mailing_list_opt_in_by_default = true no subscribe_to_lists job is triggered on Delayed_Job.

Is this the expected behavior?

Rails 4 support

Hi, is Rails 4 support planned for anytime in the near future?

Thanks!

New Release

I am planning on doing another release of this within the next week.

Update for newer Devise

Hi,

I am using Devise 2.1.2 and this gem do not support newer devise.

Any timeframe for the update?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.