Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:22:36+00:00 2026-06-03T00:22:36+00:00

I’m using the Sorcery library in a rails app. One of its modules is

  • 0

I’m using the Sorcery library in a rails app. One of its modules is for external authentication, and I need to add a method to that module.

The existing code is here, I want to add the add_provider_to_user method from this patch.

So, I added a file to my lib/modules directory, which I’ve told rails to autoload. The file is called sorcery_extension.rb and it looks like this:

module Sorcery
  module Controller
    module Submodules
      module External
        module InstanceMethods
          protected

          # If user is logged, he can add all available providers into his account
          def add_provider_to_user(provider)
            provider_name = provider.to_sym
            provider = Config.send(provider_name)
            user_hash = provider.get_user_hash
            config = user_class.sorcery_config

            user = current_user.send(config.authentications_class.to_s.downcase.pluralize).build(config.provider_uid_attribute_name => user_hash[:uid], config.provider_attribute_name => provider)
            user.save(:validate => false)

            return user
          end
        end
      end
    end
  end
end

This didn’t work. I get undefined method error in my controller (where calling the other sorcery methods works fine).

So, my basic understanding of ruby is you can add methods to an object or module at any time… I think I’ve copied the nesting of the modules correctly in the file. Do I need to name the module file something different? I’m not really sure how to do this kind of thing, so any help is much appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:22:37+00:00Added an answer on June 3, 2026 at 12:22 am

    Your file is never required. You can double check this by typing in the console:

    Sorcery::Controller::Submodules::External::InstanceMethods.method_defined?(:add_provider_to_user)
      # => will return false, you want true
    

    The reason is that auloading only happens when a constant is unknown in which case Rails will try to autoload it from the different autoloaded paths.

    You have to require your file explicitly (e.g. from a file in initializer) and things will work as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.