Search code examples
ruby-on-railsrubyruby-on-rails-4rubygemssorcery

Rails Sorcery Gem Intermittent undefined method Exceptions


I'm using the Sorcery gem (version 0.8.6) to authenticate Company records in a Rails 4.0.4 app.

The authentication flow is working fine, but I'm running into issues when trying to use Sorcery's submodules - :reset_password and :user_activation. Rails throws undefined method exceptions when calling instance methods defined in Sorcery submodules on instances of the Company record (@company):

undefined method exception

The issue exists intermittently and I can't reproduce in any logical way. 1% of the time @company will handle the method like it's supposed to, and doesn't the other 99% of the time.

In the screen above I have attempted to call deliver_reset_password_instructions!, which is defined in reset_password.rb.

My Sorcery initialiser (config/initializers/sorcery.rb) contains: Rails.application.config.sorcery.submodules = [:reset_password, :user_activation] and config.user_class = "Company".

My Company model (app/models/company.rb) contains authenticates_with_sorcery!, which if I'm correct should include these submodules and extend the model with the methods defined in any configure submodules.

Worth mentioning that the same behaviour is happening with send_activation_success_email! and all the other instance methods defined in user_activation.rb (I'm not directly calling it, but Sorcery only calls it 1% of the time on a successful Company create).

Been struggling with this for about 2 days now, have run out of ideas.

Any help is very much appreciated!

Updates

  1. I've noticed it seems to work (@company responds to submodule defined instance methods) the first time after I leave the computer and come back after a few hours. It will continue to work until the Rails server is restarted.

Solution

  • I found the problem!

    I found it! 1.5 days later.

    In my rails_admin initializer I had the lines:

    Rails.application.eager_load!
    config.included_models = ActiveRecord::Base.descendants.map!(&:name)
    

    To address the issue described: sferik/rails_admin#1697

    This didn't play well with Sorcery apparently.

    All is well now.

    More info: GitHub Issue