has_many_emails

Add multiply emails to the addressee's model without changing the email attribute behaviour.

Installation

Install the plugin

$ rails plugin install http://..

Add to you User class:

class User < ActiveRecord::Base
...
has_many_emails
...

Generate the migration:

$ rails generate has_many_emails

Or add new schema email's convertaion for User and Contact models:

$ rails generate has_many_emails -m User,Contact

Migrate.

$ rake db:migrate

It creates the email_addresses table.

Examples

> u = User.new(:name=>'Bob')
> u.email   # => nil

> u.email = '[email protected]'
> u.email    # => '[email protected]'
> u.emails   # => ['[email protected]']

> u.email = '[email protected]'  
> u.email    # => '[email protected]'
> u.emails   # => ['[email protected]']

> u.add_email '[email protected]'
> u.email    # => '[email protected]'
> u.emails   # => ['[email protected]', '[email protected]']

> u.email = '[email protected]'
> u.email    # => '[email protected]'
> u.emails   # => ['[email protected]', '[email protected]' ]

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright (c) 2010 Danil Pismenny. See LICENSE for details.