我試圖添加一個外部登錄與Facebook,但每當我意識到主頁正確指示我到Facebook頁面,但後來我得到以下錯誤,並不明白它可能是什麼。錯誤Ruby on Rails:Users :: OmniauthCallbacksController#facebook缺少此請求格式和變體的模板
「Users :: OmniauthCallbacksController#facebook缺少此請求格式和變體的模板request.formats:[」text/html「] request.variant:[]注意!對於XHR/Ajax或API請求,動作通常會以204無內容迴應:一個空的白色屏幕由於您正在將其加載到網絡瀏覽器中,因此我們認爲您期望實際渲染模板而不是無效,因此我們顯示的錯誤是額外的,如果你期待204沒有內容,繼續下去,這就是你從XHR或API請求中得到的結果,給它一個機會。「
"That's what you'll get from an XHR or API request. Give it a shot."
raise ActionController::UnknownFormat, message
else
logger.info "No template found for #{self.class.name}\##{action_name}, rendering head :no_content" if logger
super
這是我的控制器
class Users::OmniauthCallbacksController < ApplicationController
def facebook
@User = User.from_omniauth(request.env["omniauth.auth"])
if @User.persisted?
@User.remember_me = true
sign_in_and_redirect @User, event: :authentication
end
end
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 => [:facebook]
def self.from_omniauth(auth)
where(provider: auth[:provider], uid: auth[:uid]).first_or_create do |user|
if auth[:info]
user.email = auth[:info][:email]
user.name = auth[:info][:name]
end
user.password = Devise.friendly_token[0,20]
end
end
has_many :articles , :dependent => :destroy
end
和我把配置/初始化/ divise.rb此行
config.omniauth :facebook, '504432376574467', 'b2bb80641fcc2ca4d28e48c5ce*******'