0
votes

I'm getting this error: The action 'github' could not be found for Users::OmniauthCallbacksController

I've looked everywhere and tried the other suggestions on other peoples posts.

This was the post on stack overflow but they had a typo and I didn't have that same error. Devise OmniauthsController not being used

This recommendation said to check rake routes but my routes match what I'm pointing to. https://github.com/plataformatec/devise/issues/1566

Most of the other links were all similar issues and I double checked the info with mine, changed stuff and still getting errors.

Info about my code. gemfile:

gem 'omniauth-github'

config/routes.rb:

  devise_for :users, :controllers => { :omniauth_callbacks => 'users/omniauth_callbacks' }

Users::OmniauthCallbacksController:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

def github @user = User.from_omniauth(request.env["omniauth.auth"]) if @user.persisted? sign_in_and_redirect @user, event: :authentication set_flash_message(:notice, :success, kind: "Github") if is_navigational_format? else redirect_to root_path end end end

User Model:

  devise :database_authenticatable, :registerable,

:recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:github]

  def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
  user.email = auth.info.email
  user.uid = auth.uid
  user.provider = auth.provider
  user.password = Devise.friendly_token[0, 20]
  user.name = auth.info.name  #assuming the user model has a name
  user.oauth_token = auth.credentials.token
  user.image = auth.info.image #assuming the user model has an image
  user.save!
end

end

Devise initializer:

  config.omniauth :github, Rails.application.secrets.github_client_id, Rails.application.secrets.github_client_secret, scope: 'user:email'

Not sure what to do since I have the method in the Users::OmniauthCallBacks controller? Am I missing something? I've been combing through for an entire day.

1

1 Answers

0
votes

Update: somehow I had 2 users folders in the controller but one was hidden? It must have gotten messed up when I reverted to a previous repo last night. Once I removed the folder all was good!