我在我的应用程序中使用omniauth-facebook,我不太确定,但我想我的路由有问题,因为它没有达到我重定向的方法。
MyApp::Application.routes.draw do
match '/auth/facebook/callback' => 'user#create'
resources :users
require 'omniauth'
class UserController < ApplicationController
def create
if User.exists?(:condition => ["email=?",auth_hash["info"]["email"]])
self.current_user = User.find(:all,:condition => ["email=?",auth_hash["info"]["email"]])
else
self.current_user = User.new(:email => auth_hash["info"]["email"])
redirect_to 'deals#generate_ticket'
end
end
def auth_hash
request.env['omniauth.auth']
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'XXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXX',
:scope => 'email'
end
也许我在路线上遗漏了一些东西,或者我没有正确安装宝石。我会非常感谢每一位帮助。谢谢!
答案 0 :(得分:1)
您的代码看起来不错,但是:您是否在gem文件中添加了以下内容?:
gem 'omniauth'
gem 'omniauth-facebook'
你也在使用:require'omniauth',也许它应该是'omniauth-facebook'。但我建议您将gem添加到gemfile中,而不是使用require。
问候.. 祝你好运。