4

我正在使用设计,我正在尝试允许用户使用 twitter/facebook 进行注册。我很困惑,因为我不断收到 \ No route matches {:controller=>"authentications", :action=>"passthru", :provider=>:twitter, :format=>nil} missing required keys: [:provider]

路由.rb

 devise_for :users,controllers: {omniauth_callbacks: "authentications", registrations: "registrations"}

身份验证控制器.rb

class AuthenticationsController < ApplicationController
  def index
    @authentications = Authentication.all
  end

  def create
    @authentication = Authentication.new(params[:authentication])
    if @authentication.save
      redirect_to authentications_url, :notice => "Successfully created authentication."
    else
      render :action => 'new'
    end
  end

  def destroy
    @authentication = Authentication.find(params[:id])
    @authentication.destroy
    redirect_to authentications_url, :notice => "Successfully destroyed authentication."
  end
  def twitter
raise omni = request.env["omniauth.auth"].to_yaml
end
end
4

2 回答 2

16

我假设您在 User 模型中有类似下面的内容;因此,您会收到此路由错误。

devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable,
         :validatable, :omniauthable,
         :omniauth_providers => [:facebook],
         :omniauth_providers => [:twitter]

将其更改为以下内容:

devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable,
         :validatable, :omniauthable,
         :omniauth_providers => [:facebook, :twitter]
于 2013-07-07T10:28:05.727 回答
1

我正在关注github上的omniauth示例,我有

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  devise :omniauthable, :omniauth_providers => [:google]
end

但只需要一个设计线如下:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :omniauthable, :omniauth_providers => [:google]
end
于 2015-11-25T04:41:38.663 回答