Devise + Omniauth Facebook重定向到注册

我已经按照https://github.com/plataformatec/devise/wiki/OmniAuth:-概述的指南

第一轮它validation了我,签了我,并把我救了db。

我清除了浏览器历史记录并测试了其他用户。

它需要新用户登录Facebook页面,登录后会自动将其重定向到

http://localhost:3000/users/sign_up#_=_ 

并且不签名或保存到DB。 有任何想法吗?

路线

  get "static/home" devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } resources :users root 'static#home' 

User.rb

 class User  [:facebook] def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or_create do |user| user.email = auth.info.email user.password = Devise.friendly_token[0,20] user.name = auth.info.name # assuming the user model has a name #user.image = auth.info.image # assuming the user model has an image end end def self.new_with_session(params, session) super.tap do |user| if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"] user.email = data["email"] if user.email.blank? end end end protected def password_required? true end end 

devise.rb

 config.omniauth :facebook, "#######", "################" 

omn​​iauth_callbacks

 class Users::OmniauthCallbacksController  "Facebook") if is_navigational_format? else session["devise.facebook_data"] = request.env["omniauth.auth"].except('extra') redirect_to new_user_registration_url end end end 

home.html.erb

  

下面的代码是重定向他。 事实certificate这只是他的Facebook帐户。 需要知道为什么他的账户正在这样做……

  if @user.persisted? sign_in_and_redirect @user #this will throw if @user is not activated set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? else session["devise.facebook_data"] = request.env["omniauth.auth"].except('extra') redirect_to new_user_registration_url end 
 http://localhost:3000/users/sign_up#_=_ 

我有完全相同的回应。 我在本地运行服务器并查看日志,它说它无法validation客户端。

事实certificate,这是因为我使用export FACEBOOK_APP_SECRET='xxxxxxx'在本地设置了ENV键,只有当您从终端中的同一选项卡运行服务器时才会有效。

要尝试的事情:

  1. 如果使用exports来设置env键 – 从同一个选项卡运行$bin/rails s 。 可以通过在终端中键入$printenv来检查是否已设置密钥。
  2. 将env键设置为bash配置文件。 这里每天都有来自osx的明确说明 。
  3. 使用dotenv模块管理密钥。

祝一切顺利。