tl;dr

Enable unsubscribe links within your emails

Description

Some of your users don't want to hear from you or your shitty application. You can add unsubscribe links to your mail views so that your users can relieve themselves of the pain you have endured on them.

Installation

# Gemfile
gem 'toolong-dontread'
rails g tldr:install

rake db:migrate

Usage

Inside your mailer you can generate an uninstall url.

class AccountMailer < ActionMailer::Base
  def new_follower_notification(user, follower)
    ...
    token = Tldr::TokenGenerator.new(user, :new_follower_notification).token
    @unsubscribe_url = unsubscribe_url(token)
    ...
  end
end

Inside your model to test if someone is subscribed

  class User < ActiveRecord::Base
    include Tldr::Subscriber
  end

  # elsewhere
  user = User.find params[:id]
  user.subscribed_to? :new_follower_notification

Inside your controller if you are using Rails

class AccountsController < ApplicationController
  def unsubscribe
    subscription = Tldr.unsubscribe params[:token]
    redirect_to dashboard_path(subscription.values[:user]), notice: 'You have successfully been unsubscribed from that stupid ass email'
  end
end

Pushing a new gem

  1. Bump the version number in tldr\lib\version.rb
  2. gem build tldr.gemspec
  3. gem push toolong-dontread-<version-number>.gemspec

Contributing

  1. Clone the repository git clone https://github.com/brilliantfantastic/tldr
  2. Create a feature branch git checkout -b my-awesome-feature
  3. Codez!
  4. Commit your changes (small commits please)
  5. Push your new branch git push origin my-awesome-feature
  6. Create a pull request hub pull-request -b brilliantfantastic:master -h brilliantfantastic:my-awesome-feature