subscribe checkbox on rails site

Is there anyone who can walk me through the process of adding a subscriber to a list if they checked the add me box on the sign up form for a client's website please?

Even down to the details of where to put the require CreateSend stuff. Nothing I'm doing seems to be working.

The documentation in the Ruby wrapper says to look at the tests to figure out how to do it. But I don't think I'm quite getting the whole process.


jamesd jamesd, 5 years ago

Hey Gabe,

Assuming you have the latest version of the createsend gem, in plain ruby you can add a subscriber like so:

require 'createsend'
CreateSend.base_uri ""
CreateSend.api_key "your api key"

  CreateSend::Subscriber.add 'your list id', 'their email address', 'their name', [], true
  rescue Exception => e
  p "Error: #{e}"

Hope that helps. Should be pretty simple to adapt that for your rails app.

gabe1k, 5 years ago

Thank you, I didn't figure out I had to put in the base_uri. I guess I assumed the ruby wrapper took care of that.

I'll try it monday and report how it went.

jamesd jamesd, 5 years ago

Hey Gabe,

That line shouldn't actually be required. For example:

$ gem install createsend
Successfully installed createsend-0.3.0
1 gem installed
Installing ri documentation for createsend-0.3.0...
Installing RDoc documentation for createsend-0.3.0...
$ irb
>> require 'createsend'
=> true
?> CreateSend.api_key "your api key"
=> {:password=>"x", :username=>"your api key"}
>> CreateSend::Subscriber.add 'your list id', '', 'their name', [], true
=> ""
gabe1k, 5 years ago

Not sure why it's not working. Works fine in the irb just like your example and even adds the person to the list.

But doesn't work in my code either in dev or production. Also when I do require 'createsend' in the rails console i get nil.

Here is my code on my create method:

require 'createsend'
CreateSend.api_key "<my key is here and works bc it worked in irb>"
CreateSend::Subscriber.add '<my list id here>', '#{}', '#{@user.full_name}', [], true
jamesd jamesd, 5 years ago

If you are using any other gems other than createsend, which are working in your app, I would suggest adding your dependency to the createsend gem in exactly the same way you have for any other gems which are working. This obviously depends on how your app is set up.

This is more of question about your rails app setup, rather than a Campaign Monitor API question, and could apply to any gem as far as I can tell from what you have posted.

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free