简体   繁体   English

路由错误 - 没有路由匹配[GET]“/ auth / twitter”Omniauth-twitter与设计宝石

[英]Routing Error - No route matches [GET] “/auth/twitter” Omniauth-twitter with devise gem

I'm trying to install omniauth-twitter and encountering some issues, mainly with the one outlined above. 我正在尝试安装omniauth-twitter并遇到一些问题,主要是上面提到的问题。 Initially I didn't have this issue but now I do so I'm scratching my head as to why this has cropped up. 最初我没有这个问题,但现在我这样做了,我正在摸不着为什么会出现这个问题。 I've placed the consumer key and secret key in the secrets.yml file and also in my omniauth.rb file as copied below. 我已将使用者密钥和密钥放在secrets.yml文件中,也放在我的omniauth.rb文件中,如下所示。 I've read an awful lot of conflicting information as to whether this file is required and all this information goes into the devise.rb file. 我已经阅读了很多相互矛盾的信息,关于这个文件是否是必需的,所有这些信息都会进入devise.rb文件。 I haven't altered or placed any reference to omniauth in my devise.rb file. 我没有在我的devise.rb文件中更改或放置对omniauth的任何引用。 I have also ensured the appropriate url callback link ( http://127.0.0.1:3000/auth/twitter/callback ) has been placed in the twitter developers site. 我还确保在twitter开发者网站上放置了相应的url回调链接( http://127.0.0.1:3000/auth/twitter/callback )。

Here's my code - 这是我的代码 -

routes.rb 的routes.rb

Rails.application.routes.draw do


  get "/auth/:provider/callback" => "social_logins#create"

  devise_for :users, :controllers => { registrations: 'registrations' }  



  resources :users
  resources :events do

    resources :bookings
  end
  # get 'welcome/index'


  authenticated :user do
    root 'events#index', as: "authenticated_root"
  end


    root 'welcome#index'


end

social_logins.controller.rb social_logins.controller.rb

class SocialLoginsController < ApplicationController
  def create


    @details = request.env["omniauth.auth"].to_yaml

    @provider = @details["provider"]
    @provider_id = @details["uid"]

    @user = User.where(provider: @provider, provider_id: @provider_id).first

    if @user.present?
        #sign them in
    else
        # make a new user
        @user = User.new
        @user.provider = @provider
        @user.provider_id = @provider_id

        # because of has_secure_password - will this work?
        @user.password = "AAAAAA!!"
        @user.password_confirmation = "AAAAAA!!"

        # let's save the key and secret
        @user.key = @details["credentials"]["token"]
        @user.secret = @details["credentials"]["secret"]

        # lets fill in their details
        @user.name = @details["info"]["name"]
        @user.email = @details["info"]["email"] || "aaaaa@email.com"

        @user.save!
    end


        session[:uid] = @user.id 
        flash[:success] = "You've logged in"
        redirect_to root_path
    end

end

index.html.erb index.html.erb

<header>
 <nav>
            <div class="links">
                <%= link_to 'Sign up', new_user_registration_path %>
                <%= link_to 'Sign in', new_user_session_path %>
                <%= link_to 'Go to Events', events_path %>
                <%= link_to "Log in with Twitter", "/auth/twitter" %>
            </div>

 </nav>         


</header>

omniauth.rb omn​​iauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, Rails.application.secrets.twitter_api_key, Rails.application.secrets.twitter_api_secret
end

你的用户模型中有这个吗?

devise omniauth_providers: [:twitter]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM