0

I'm using devise and started to implement omniauth-instagram. However, I keep getting an error that reads:

uninitialized constant Users::Auth::Instagram::CallbackController

I'm not sure which part of my configuration is incorrect so I've included some excerpts from my routes.db , omniauth_callbacks_controllers.rb, and devise.rb for reference.

Any points in the right direction would be greatly appreciated!

routes.db
devise_for :users, :controllers => { :omniauth_callbacks => "users/auth/instagram/callbacks" }

/controllers/users/omniauth_callbacks_controllers.rb

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def instagram

      # You need to implement the method below in your model (e.g. app/models/user.rb)
      @user = User.find_for_oauth(request.env["omniauth.auth"], current_users)

      if @user.persisted?
        sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
        set_flash_message(:notice, :success, :kind => "Instagram") if is_navigational_format?
      else
        session["devise.instagram_data"] = request.env["omniauth.auth"]
        redirect_to new_user_registration_url
      end

  end

end

devise.rb
config.omniauth_path_prefix = 'users/auth/instagram/callbacks'

veryrarecandy
  • 323
  • 1
  • 4
  • 16

2 Answers2

0

If you see your devise.rb:

config.omniauth_path_prefix = 'users/auth/instagram/callbacks'

and your routes.rb:

devise_for :users, :controllers => { :omniauth_callbacks => "users/auth/instagram/callbacks" }

both points to Users::Auth::Instagram::CallbacksController

while you have defined:

class Users::OmniauthCallbacksController

inside /controllers/users/omniauth_callbacks_controllers.rb

this should be: /controllers/users/auth/instagram/callbacks_controllers.rb

and your class should change to:

class Users::Auth::Instagram::CallbackController < Devise::OmniauthCallbacksController

Or remove /auth from both(routes.rb and devise.rb) the places and see if it works?

Surya
  • 14,897
  • 2
  • 44
  • 70
  • Hrm... I tried both your suggestions above and still couldn't get it to work. – veryrarecandy Apr 29 '14 at 17:54
  • is there something else I should be checking out? When I take my browser to `http://localhost:3000/users/auth/instagram/callbacks` I get a Routing Error that **No route matches [GET] 'users/auth/instagram/callbacks'** Even though when I scroll down I see this route does exist. – veryrarecandy Apr 29 '14 at 17:56
  • 1
    My bad, I didn't notice to mention that you need to rename your `/controllers/users/omniauth_callbacks_controllers.rb` to `/controllers/users/auth/instagram/callbacks_controllers.rb`. I hope you've got this working anyways. I'll update in answer. – Surya Apr 30 '14 at 08:11
0

Realized my naming convention was incorrect!

With the help of this previous question, I realized that my file name was not matching the class name my routes and paths were referring to.

For example, routes.rb and devise.rb were both referring to path:
"users/auth/instagram/callbacks"

My classes file name before and after:
users/auth/instagram/omniauth_callbacks_controllers.rb
users/auth/instagram/callbacks_controllers.rb

It's also important to note that the classname within my callbacks_controllers.rb also, appropriately, reflect the path of the file:
class Users::Auth::Instagram::CallbacksController

Community
  • 1
  • 1
veryrarecandy
  • 323
  • 1
  • 4
  • 16