【问题标题】:Rails 4 error with twitter/Facebook authentication. Devise使用 Twitter/Facebook 身份验证的 Rails 4 错误。设计
【发布时间】:2013-06-14 00:45:11
【问题描述】:

我正在与 devise 合作,我正在尝试允许用户使用 twitter/facebook 进行注册。我很困惑,因为我不断得到\ 没有路由匹配 {:controller=>"authentications", :action=>"passthru", :provider=>:twitter, :format=>nil} 缺少必需的键:[:provider]

Routes.rb

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

AuthenticationController.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

【问题讨论】:

标签: ruby-on-rails devise twitter omniauth facebook-authentication


【解决方案1】:

我假设您在 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]

【讨论】:

    【解决方案2】:

    我关注了omniauth example on github,我有

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-23
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 2013-10-10
      • 1970-01-01
      相关资源
      最近更新 更多