【发布时间】:2014-08-26 21:35:37
【问题描述】:
我正在按照在线教程将 facebook omniauth 合并到示例应用程序中,然后再将其添加到我的 ROR 应用程序(http://richonrails.com/articles/facebook-authentication-in-ruby-on-rails 和 https://coderwall.com/p/bsfitw),但是当我访问“登录来自脸书链接”。
ArgumentError in SessionsController#create wrong number of arguments (1 for 2).
这是我的用户模型(直接来自教程),错误似乎来自哪里,第 3 行突出显示为源
class User < ActiveRecord::Base
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
end
会话控制器
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to root_url
end
def destroy
session[:user_id] = nil
redirect_to root_url
end
end
我没有第二个教程中的咖啡脚本,当我使用它时出现不同的错误。
任何帮助将不胜感激。
【问题讨论】:
-
我不确定它是否能解决您的问题,但似乎
first_or_initialize不需要tap方法 -
只是为了好玩,我删除了水龙头并没有产生任何影响。我确实尝试过使用配置文件并最终得到了这个错误 { "error": { "message": "Missing client_id parameter.", "type": "OAuthException", "code": 101 } }
-
我现在正试图弄清楚一个在另一个之前,或者它们是否完全不相关。我从 FB 而不是 Rails 得到的新错误。
-
是的,我确实用谷歌搜索了错误并更改了我的配置文件
标签: ruby-on-rails ruby ruby-on-rails-4 omniauth omniauth-facebook