Routing Error uninitialized constant Users

前端 未结 2 974
北恋
北恋 2021-02-03 23:00

I am a rails newbie... I am trying to set up Sign in with facebook for a demo app. I am using OmniAuth and following this tutorial

https://github.com/plataformatec/devi

2条回答
  •  不知归路
    2021-02-03 23:50

    I believe that part is messing up:

    match '/users/auth/facebook' => 'users/omniauth_callbacks#passthru'
    

    Little test, for you:

    put in your view:

    <%= link_to users_auth_facebook_path, users_auth_facebook_path  %>
    

    and follow it with click, it also gives very same error...

    I believe you should use something like (what is mentioned in wiki you linked above):

    devise_scope :user do
      get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
    end
    

    And wrap passthru method to delegate action to appropriate private/protected method depending on params[:provider] value

    class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
      def passthru
        send(params[:provider]) if providers.include?(params[:provider])
      end
    
      protected
    
      def facebook
        raise "Implement me for facebook"
      end
    
      def twitter
        raise "Implement me for twitter"
      end
    
      private
    
      def providers
        ["facebook", "twitter"]
      end
    end
    

提交回复
热议问题