uninitialized constant Users::Auth::Instagram::CallbackController -- Not sure which part of configuration is incorrect

StackOverflow https://stackoverflow.com/questions/23359174

Pergunta

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'

Foi útil?

Solução

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

Outras dicas

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?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top