The action 'twitter' could not be found for Devise::OmniauthCallbacksController

349 views Asked by At

I am trying to integrate twitter with devise in my rails application.

However, I get this error The action 'twitter' could not be found for Devise::OmniauthCallbacksController

My routes file contains:

  devise_for :conrollers => {:omniauth_callbacks =>  "omniauth_callbacks"}

I have seen a few thread but not quite able to fix this issue. Please help. This is my controller

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def twitter
    raise request.env["omniauth.auth"].to_yaml
end

#alias_method :twitter, :all

end

3

There are 3 answers

2
NM Pennypacker On

Since Devise::OmniauthCallbacksController inherits from DeviseController, why not just add your twitter method DeviseController?

class DeviseController
  def twitter
    raise request.env["omniauth.auth"].to_yaml
  end
end

or you could do:

class Devise::OmniauthCallbacksController
  def twitter
    raise request.env["omniauth.auth"].to_yaml
  end
end

or if you have a controllers/devise directory, this might work:

module Devise
  class OmniauthCallbacksController
    def twitter
      raise request.env["omniauth.auth"].to_yaml
    end
  end
end
0
Maruf Hasan Bulbul On

You should have a devise call in User model. Just add another params there

devise :database_authenticatable, :registerable, :confirmable.......
       ......., :omniauth_providers: [:twitter]
0
Jen V. On

I got the same error message and this is how I fixed it. I defined a Twitter method in the OmniauthCallbacksController file

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  skip_before_action :verify_authenticity_token

  def sign_in_with(provider_name)
    @user = User.from_omniauth(request.env["omniauth.auth"])
    sign_in_and_redirect @user, :event => :authentication
    set_flash_message(:notice, :success, :kind => provider_name) if is_navigational_format?
  end

  def facebook
    sign_in_with "Facebook"
  end
  def github
    sign_in_with "Github"
  end

  def linkedin
    sign_in_with "LinkedIn"
  end

  def twitter
    sign_in_with "Twitter"
  end

  def google_oauth2
    sign_in_with "Google"
  end

  def developer
    sign_in_with "Developer"
  end
end