【发布时间】:2016-09-22 11:45:39
【问题描述】:
我安装了 Devise 身份验证,没有任何问题。现在我正在尝试添加一个使用 Omniauth-facebook 登录 Facebook 的选项。
我按照this guide 中的说明进行操作,但在访问网址localhost:3000/auth/facebook 时,我收到有关缺少“Passthru”文档的错误。
这是我得到的第一个错误:
Unknown action
The action 'passthru' could not be found for RegistrationsController
我尝试通过向我的控制器添加一个空的“passthru”操作来进行创可贴修复:
def passthru
end
这解决了这个错误,但我得到了一个不同的回报:
Template is missing
Missing template registrations/passthru, devise/registrations/passthru, devise/passthru, application/passthru with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/home/user/project/app/views" * "/home/user/.rvm/gems/ruby-2.0.0-p648@railstutorial_rails_4_0/gems/devise-3.5.2/app/views"
我尝试在所述文件夹中创建“passthru.html.erb”,但该错误仍然存在。无论如何,我认为这些错误象征着更深层次的问题。
还有其他人遇到过这个问题吗?我只能在上面找到this SO question,但没有一个答案有帮助。
到目前为止我的代码:
宝石文件
gem 'devise'
gem 'omniauth-facebook'
gem 'omniauth'
routes.rb
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: 'registrations' }
member.rb
devise :database_authenticatable, :registerable,
:omniauthable, :omniauth_providers => [:facebook]
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |member|
member.email = auth.info.email
member.password = Devise.friendly_token[0,20]
member.title = auth.info.name
end
end
registrations_controller.rb
def facebook
@member = Member.from_omniauth(request.env["omniauth.auth"])
if @member.persisted?
sign_in_and_redirect @member, :event => :authentication
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_member_registration_url
end
end
def failure
redirect_to root_path
end
def passthru
end
initializers/devise.rb
config.omniauth :facebook, "<app_id>", "<app_secret>"
【问题讨论】:
-
请描述你想通过
passthru方法实现什么? -
@PraveshKhatri 我不想用它做任何事情。该文档也没有说明任何关于 passthru 的内容。我认为这是一个旧版本的omniauth的遗物。
标签: ruby-on-rails facebook devise omniauth omniauth-facebook