0

I'm trying to get ApiAuth working with ActiveResource and having no luck. The documentation suggests this as the way to use the gem:

class Foo < ActiveResource::Base
  with_api_auth("foo", "bar")
end

This results in the following error:

NoMethodError: undefined method `with_api_auth' for Foo:Class

I know that the api_auth library is available because when I do

require 'api_auth' 

i get "false", which I believe means that the library/gem was already loaded.

Additionally, I picked out the module/class where with_api_auth is defined and don't get an error:

2.3.8 :004 > 
ApiAuth::Rails::ActiveResourceExtension::ActiveResourceApiAuth
=> ApiAuth::Rails::ActiveResourceExtension::ActiveResourceApiAuth
2.3.8 :005 >

I found a couple issues for this exact error on the api_auth github project, but neither had solutions that worked for me.

Anyone else see this error or know how to eliminate it?

jaydel
  • 14,389
  • 14
  • 62
  • 98
  • https://github.com/mgomes/api_auth/issues/28 Does this help? What's your Gemfile entry for this? – Anuj Khandelwal Jul 02 '19 at 12:11
  • No, that didn't fix things for me. However, github.com/mgomes/api_auth/issues/113 did actually send me down the right path. I'm putting up my solution as the answer to my question. – jaydel Jul 02 '19 at 12:22

1 Answers1

1

So in the end it was an ordering of gems in my Gemfile that made the difference. It ended up being an ordering issue in my Gemfile. I found an issue (113) on the gem github issues list that said to make sure the order was right by doing:

gem 'activeresource'
gem 'api-auth'

Originally this hadn't worked and it ended up being because you no longer have to explicitly put activeresource in your Gemfile. So I moved gem 'api-auth' the last line in my Gemfile and everything worked.

I don't know for sure, but I think it has to do with how mixins are loaded on bundle install. "think" being the most important word in that statement.

Anuj Khandelwal
  • 1,214
  • 1
  • 8
  • 16
jaydel
  • 14,389
  • 14
  • 62
  • 98
  • yeah, you're right active resource needs to be loaded first in the Rails environment in order to register api auth with active resource. Check this out https://github.com/mgomes/api_auth/blob/master/lib/api_auth/railtie.rb#L81, you'll find that api auth is looking for active resource and registering the api auth extensions with active resource. – Anil Cherukuri Aug 08 '19 at 20:11