Code Monkey home page Code Monkey logo

devise-multi_email's Introduction

Devise::MultiEmail Build Status Coverage Status

Letting Devise support multiple emails, allows you to:

  • Login with multiple emails
  • Send confirmations to multiple emails
  • Recover the password with any of the emails
  • Validations for multiple emails

:multi_email_authenticatable, :multi_email_confirmable and :multi_email_validatable are provided by devise-multi_email.

Getting Started

Add this line to your application's Gemfile:

gem 'devise-multi_email'

Suppose you have already setup Devise, your User model might look like this:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable
end

In order to let your User support multiple emails, with devise-multi_email what you need to do is just:

class User < ActiveRecord::Base
  has_many :emails

  # Replace :database_authenticatable, with :multi_email_authenticatable
  devise :multi_email_authenticatable, :registerable
end

class Email < ActiveRecord::Base
  belongs_to :user
end

Note that the :email column should be moved from users table to the emails table, and a new primary boolean column should be added to the emails table (so that all the emails will be sent to the primary email, and user.email will give you the primary email address). Your emails table's migration should look like:

create_table :emails do |t|
  t.integer :user_id
  t.string :email
  t.boolean :primary
 end

You can choose whether or not users can login with an email address that is not the primary email address.

Devise::MultiEmail.configure do |config|
  # Default is `false`
  config.only_login_with_primary_email = true
end

The autosave is automatically enabled on the emails association by default. This is to ensure the primary flag is persisted for all emails when the primary email is changed. When autosave is not enabled on the association, only new emails are saved when the parent (e.g. User) record is saved. (Updates to already-persisted email records are not saved.)

If you don't want autosave to be enabled automatically, you can disable this feature. What this will do is enable alternative behavior, which adds an after_save callback to the parent record and calls email.save on each email record where the primary value has changed.

Devise::MultiEmail.configure do |config|
  # Default is `true`
  config.autosave_emails = false
end

Configure custom association names

You may not want to use the association user.emails or email.users. You can customize the name of the associations used. Add your custom configurations to an initializer file such as config/initializers/devise-multi_email.rb.

Note: model classes are inferred from the associations.

Devise::MultiEmail.configure do |config|
  # Default is :user for Email model
  config.parent_association_name = :team
  # Default is :emails for parent (e.g. User) model
  config.emails_association_name = :email_addresses
  # Default is :primary_email_record
  config.primary_email_method_name = :primary_email
end

# Example use of custom association names
team = Team.first
emails = team.email_addresses

email = EmailAddress.first
team = email.team

Confirmable with multiple emails

Sending separate confirmations to each email is supported. What you need to do is:

Declare devise :multi_email_confirmable in your User model:

class User < ActiveRecord::Base
  has_many :emails

  # You should not declare :confirmable and :multi_email_confirmable at the same time.
  devise :multi_email_authenticatable, :registerable, :multi_email_confirmable
end

Add :confirmation_token, :confirmed_at and :confirmation_sent_at to your emails table:

create_table :emails do |t|
  t.integer :user_id
  t.string :email
  t.boolean :primary, default: false

  ## Confirmable
  t.string :unconfirmed_email
  t.string :confirmation_token
  t.datetime :confirmed_at
  t.datetime :confirmation_sent_at
end

Then all the methods in Devise confirmable are available in your Email model. You can do email#send_confirmation_instructions for each of your email. And user#send_confirmation_instructions will be delegated to the primary email.

Validatable with multiple emails

Declare devise :multi_email_validatable in the User model, then all the user emails will be validated:

class User < ActiveRecord::Base
  has_many :emails

  # You should not declare :validatable and :multi_email_validatable at the same time.
  devise :multi_email_authenticatable, :registerable, :multi_email_validatable
end

You can find the detailed configurations in the rails 5 example app.

ActiveJob Integration

The Devise README describes how to use ActiveJob to deliver emails in the background. Normally you would place the following code in your User model, however when using devise-multi_email you should place this in the Email model.

# models/email.rb
def send_devise_notification(notification, *args)
  devise_mailer.send(notification, self, *args).deliver_later
end

What's more

The gem works with all other Devise modules as expected -- you don't need to add the "multi_email" prefix.

class User < ActiveRecord::Base
  devise :multi_email_authenticatable, :multi_email_confirmable, :multi_email_validatable, :lockable,
         :recoverable, :registerable, :rememberable, :timeoutable, :trackable
end

Issues

You need to implement add/delete emails for a user as well as set/unset "primary" for each email.

You can do email.send_confirmation_instructions for each email individually, but you need to handle that logic in some place (except for the primary email, which is handled by Devise by default). e.g. After a new email was added by a user, you might want to provide some buttons in the view to allow users to resend confirmation instructions for that email.

Wiki

Migrating existing user records

Development

After checking out the repo, run bundle install to install dependencies.

Then, run bundle exec rake to run the RSpec test suite.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/allenwq/devise-multi_email. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

devise-multi_email's People

Contributors

allenwq avatar dependabot[bot] avatar fonglh avatar jeremylynch avatar joelvh avatar mgmodell avatar olleolleolle avatar sandydoo avatar swrobel avatar thiagogabriel avatar tmfnll 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

Watchers

 avatar  avatar

devise-multi_email's Issues

Can we please get a new release?

I do not know the level of effort involved in pushing out a new release, but I'd love to see a new version of this gem show up as HEAD includes fixes that would remove a deprecation warning in rails 6 and (presumably) allow it to continue to function in later versions. I'll gladly help out with the release if it is a matter of time available.

Allow resetting password with any email

Currently, devise mailer sends the reset password instructions email to the resource email:
https://github.com/heartcombo/devise/blob/29943a26e61d68198666c59e07457dba3c75f581/lib/devise/mailers/helpers.rb#L34

But with multiple emails, you might want to get the reset password instructions to the email you entered, regardless of whether it's your primary email or not, right? In that case the email to should be set to opts[:email] instead.

Should we override this method? Is that something we are interested in doing?

Move from travis-ci.org to travis-ci.com

Thanks for creating and maintaining this gem.

Travis is not building anymore on travis-ci.org. You may need to migrate to travis-ci.com and also update the README with the new badge.

Another solution would be moving to GitHub Actions, but should take longer to make it work.

The error message present on https://travis-ci.org/github/allenwq/devise-multi_email/builds:

Since June 15th, 2021, the building on travis-ci.org is ceased. Please use travis-ci.com from now on.

Fix Rails 6.1 deprecation warning

Rails 6.1 deprecated errors.keys and instead recommends errors.attribute_names.

validatable.rb uses errors.keys directly and ought to use errors.attribute_names when in Rails 6+.

Add documentation to readme for existing users

I used this method to migrate my emails from the email field to the emails table:

def update_emails
  existing_email = self.read_attribute_before_type_cast('email')
  if email == nil && existing_email != ''
    email = Email.new(email: existing_email, user: self, primary: true)
    email.skip_confirmation!
    email.save
    if email.errors.present?
      return errors
    end
    logger.info 'Email Updated!'
  else
    logger.info 'Email already exists or no email saved on record'
  end
end

In Rails console:

User.find_each(&:update_emails)

Perhaps we could include this in the readme?

Emails are not passed to Devise's parameter_filter for downcase

find_first_by_auth_conditions deletes the email from the tainted_conditions hash, so it doesn't go to devise_parameter_filter for downcasing.

The suggestion below works for case insensitive login but has not been tested in other scenarios.

def find_first_by_auth_conditions(tainted_conditions, opts = {})
          tainted_conditions = tainted_conditions.dup
          email = tainted_conditions[:email]
          if email && email.is_a?(String)
            conditions = devise_parameter_filter.filter(tainted_conditions).to_h.merge(opts)
            conditions = { emails: conditions }

            resource = joins(:emails).find_by(conditions)
            resource.current_login_email = email if resource.respond_to?(:current_login_email=)
            resource
          else
            super(tainted_conditions, opts)
          end
        end

References Coursemology/coursemology2#1292

Names of the model

Hi,
Just wanted to confirm that the names of the models should necessariy be User and Emails ?
I created a model called "Team" and "Email" and when I create an email, I get an exception

Email: Association :user not found: Have you declared that ?

Emails is invalid

I can't register new user. I always get the Emails is invalid error.

Initializer not working for version specified on Rubygems

I wrote an initializer like suggested on the readme:

# config/initializers/devise-multi_email.rb

Devise::MultiEmail.configure do |config|
  config.emails_association_name = :user_emails
  # Default is :primary_email_record
  # config.primary_email_method_name = :primary_email
end

I'm using the following version in the gemfile, that I got from rubygems:
gem 'devise-multi_email', '~> 1.0', '>= 1.0.2'

And I get
Undefined method configure' for Devise::MultiEmail:Module (NoMethodError)`

Now for later versions like 2.0 it works fine, but it is not the one on Rubygems

Change primary email method

If a user has 2 emails, how can they change their primary email?

I tried to do the following:

@email.primary = true
@email.save

This does work, however, the original primary email remains as a primary email record. Could we add validations to ensure that a user has only one primary email?

Cant login after moving all email to new table

Hi,
I just added multi email gem and facing with 2 problem atm.
1 - After move all email to new table, i try to login and got another error

BCrypt::Errors::InvalidHash at /users/sign_in
invalid hash

2- After submit new user, i got this error

NoMethodError at /users undefined method limit' for nil:NilClass`

at this line user.valid?

in user model, i have no email validates but validates :email, uniqueness: true

I did everything exactly like Readme. Where did i go wrong?

undefined method `devise' for Email

I have tried adding using devise-multi_email with association other than user.
getting undefined method `devise' for Email (call 'Email.connection' to establish a connection):Class (NoMethodError)

undefined method devise' for Email (call 'Email.connection' to establish a connection):Class (NoMethodError) from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/models/confirmable.rb:9:in block in module:EmailConfirmable'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in class_eval' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in append_features'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/association_manager.rb:14:in include' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/association_manager.rb:14:in include_module'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/models/confirmable.rb:40:in block in <module:ConfirmableExtensions>' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in class_eval'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in append_features' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/models/confirmable.rb:29:in include'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-multi_email-2.0.1/lib/devise/multi_email/models/confirmable.rb:29:in block in <module:MultiEmailConfirmable>' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in class_eval'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concern.rb:120:in append_features' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:103:in include'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:103:in block (2 levels) in devise' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:87:in each'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:87:in block in devise' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:114:in devise_modules_hook!'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/models.rb:84:in devise' from /home/shruti/api_v3/app/models/fields/fields_talent.rb:48:in block in included'
from /home/shruti/api_v3/app/models/fields/fields_talent.rb:5:in class_eval' from /home/shruti/api_v3/app/models/fields/fields_talent.rb:5:in included'
from /home/shruti/api_v3/app/models/talent.rb:12:in include' from /home/shruti/api_v3/app/models/talent.rb:12:in class:Talent'
from /home/shruti/api_v3/app/models/talent.rb:2:in <top (required)>' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:476:in load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:476:in block in load_file' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:661:in new_constants_in'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:475:in load_file' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:374:in block in require_or_load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:36:in block in load_interlock' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:12:in block in loading'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:149:in exclusive' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:11:in loading'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:36:in load_interlock' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:357:in require_or_load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:510:in load_missing_constant' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:202:in const_missing'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:in const_get' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:269:in block in constantize'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in each' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in inject'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/inflector/methods.rb:267:in constantize' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:582:in get'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:613:in constantize' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise.rb:313:in get'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:81:in to' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:76:in modules'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:93:in routes' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:160:in default_used_route'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/mapping.rb:70:in initialize' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise.rb:343:in new'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise.rb:343:in add_mapping' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/rails/routes.rb:241:in block in devise_for'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/rails/routes.rb:240:in each' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/devise-4.3.0/lib/devise/rails/routes.rb:240:in devise_for'
from (eval):1:in draw' from /home/shruti/api_v3/config/routes.rb:3:in instance_eval'
from /home/shruti/api_v3/config/routes.rb:3:in draw' from /home/shruti/api_v3/config/routes.rb:9:in block in <top (required)>'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in instance_exec' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in eval_block'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:408:in draw' from /home/shruti/api_v3/config/routes.rb:7:in <top (required)>'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in load' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in block in load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in load_dependency' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:286:in load'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in block in load_paths' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in each'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in load_paths' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:18:in reload!'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:41:in block in updater' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/activesupport-5.1.4/lib/active_support/file_update_checker.rb:81:in execute'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:42:in updater' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:31:in execute_if_updated'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application/finisher.rb:128:in block in <module:Finisher>' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/initializable.rb:30:in instance_exec'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/initializable.rb:30:in run' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/initializable.rb:59:in block in run_initializers'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:228:in block in tsort_each' from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:350:in block (2 levels) in each_strongly_connected_component'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:431:in each_strongly_connected_component_from' from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:349:in block in each_strongly_connected_component'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in each' from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in call'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in each_strongly_connected_component' from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:226:in tsort_each'
from /usr/share/rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:205:in tsort_each' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/initializable.rb:58:in run_initializers'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/application.rb:353:in initialize!' from /home/shruti/api_v3/config/environment.rb:5:in <top (required)>'
from config.ru:1:in require_relative' from config.ru:1:in block in

'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/builder.rb:55:in instance_eval' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/builder.rb:55:in initialize'
from config.ru:in new' from config.ru:in '
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/builder.rb:49:in eval' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/builder.rb:49:in new_from_string'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/builder.rb:40:in parse_file' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/server.rb:319:in build_app_and_options_from_config'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/server.rb:219:in app' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:24:in app'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/rack-2.0.3/lib/rack/server.rb:354:in wrapped_app' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:80:in log_to_stdout'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:42:in start' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in block in perform'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in tap' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in perform'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/thor-0.20.0/lib/thor/command.rb:27:in run' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/thor-0.20.0/lib/thor/invocation.rb:126:in invoke_command'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/thor-0.20.0/lib/thor.rb:387:in dispatch' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/command/base.rb:63:in perform'
from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/command.rb:44:in invoke' from /home/shruti/.rvm/gems/ruby-2.4.2@apis/gems/railties-5.1.4/lib/rails/commands.rb:16:in <top (required)>'
from bin/rails:4:in `require'

Gotchas with using polymorphic belongs_to :owner for emails?

I have a data model where multiple objects can have emails, so my Email class has a polymorphic :owner rather than a belongs_to :user association (as illustrated below). in my preliminary tests, i was pleasantly surprised to find that devise and devise-multi_email mostly worked out-of-the-box for this use case (:invitable breaks and found a separate bug (#18)). is this a use case that's officially supported (in which case it would be nice to see it mentioned in the documentation) or do i need to be on the lookout for breakages?

# app/models/user.rb
class User < ApplicationRecord
  has_many :emails, as: :owner
  devise   :multi_email_authenticatable, ...
  ...
end
# app/models/email.rb
class Email < ApplicationRecord
  belongs_to :owner, polymorphic: true, optional: true
  ...
end

thanks!

README is wrong about send_devise_notification method placement

The following part of the README:

The [Devise README](https://github.com/plataformatec/devise#activejob-integration) describes how to use ActiveJob to deliver emails in the background. Normally you would place the following code in your `User` model, however when using _devise-multi_email_ you should place this in the `Email` model.

does not seem to be correct. If I put the method send_devise_notification on the Email model, the debugger does not hit it. If I place it on the User model, the debugger stops. Should we drop this part of the README?

integration with devise_token_auth

I'm trying to migrate from a functional devise+omniauth+devise-multi-email install to bring in devise_token_auth but I seem to be running into a problem between devise-multi_email and devise_token_auth. I've submitted an issue to them, but I'm wondering if you might be able to verify that my understanding is correct and let me know if a change should be made here or there?

Multi email invitable module needs to delegate to configured `primary_email_method_name`

this line in the confirmable.rb model file needs to be updated to sync up with the newly configurable primary_email_method_name:

instead of

... to: :primary_email_record ...

it should be changed to

... to: Devise::MultiEmail.primary_email_method_name ...

if your method name is primary_email as is now recommended, then that line throws this error:

undefined local variable or method `primary_email_record' for #<User:0x00...>

changing it as above makes the error go away.

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.