Ruby on rails Omniauth facebook和Desive:“;“缺少直通器”;错误
我已经设计了身份验证,安装没有问题。现在我正在尝试添加一个使用Omniauth Facebook登录Facebook的选项 我按照中的说明进行了操作,但是在访问urlRuby on rails Omniauth facebook和Desive:“;“缺少直通器”;错误,ruby-on-rails,facebook,devise,omniauth,omniauth-facebook,Ruby On Rails,Facebook,Devise,Omniauth,Omniauth Facebook,我已经设计了身份验证,安装没有问题。现在我正在尝试添加一个使用Omniauth Facebook登录Facebook的选项 我按照中的说明进行了操作,但是在访问urllocalhost:3000/auth/facebook时,我遇到了关于缺少“Passthru”文档的错误 这是我遇到的第一个错误: Unknown action The action 'passthru' could not be found for RegistrationsController 我尝试了绷带修复,只是在控制器
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”,但错误仍然存在。无论如何,我认为这些错误象征着一个更深层次的问题
还有其他人遇到过这个问题吗?我只能在上面找到答案,但没有一个答案是有用的
到目前为止我的代码: Gemfile
gem 'devise'
gem 'omniauth-facebook'
gem 'omniauth'
routes.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
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
config.omniauth :facebook, "<app_id>", "<app_secret>"
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access'}
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks" }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
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
skip_before_filter :authenticate_user!
def facebook
p env["omniauth.auth"]
user = User.from_omniauth(env["omniauth.auth"])
if user.persisted?
flash[:notice] = "You are in..!!!"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
def failure
#handle you logic here..
#and delegate to super.
super
end
Devise.setup do |config|
config.omniauth :facebook, "KEY", "SECRET"
end
Rails.application.routes.draw do
devise_for :users
resources :users
end
设计用于:成员、控制器:{registrations:'registrations',omniauth\u回调:'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
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
config.omniauth :facebook, "<app_id>", "<app_secret>"
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access'}
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks" }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
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
skip_before_filter :authenticate_user!
def facebook
p env["omniauth.auth"]
user = User.from_omniauth(env["omniauth.auth"])
if user.persisted?
flash[:notice] = "You are in..!!!"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
def failure
#handle you logic here..
#and delegate to super.
super
end
Devise.setup do |config|
config.omniauth :facebook, "KEY", "SECRET"
end
Rails.application.routes.draw do
devise_for :users
resources :users
end
注册\u controller.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
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
config.omniauth :facebook, "<app_id>", "<app_secret>"
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access'}
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks" }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
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
skip_before_filter :authenticate_user!
def facebook
p env["omniauth.auth"]
user = User.from_omniauth(env["omniauth.auth"])
if user.persisted?
flash[:notice] = "You are in..!!!"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
def failure
#handle you logic here..
#and delegate to super.
super
end
Devise.setup do |config|
config.omniauth :facebook, "KEY", "SECRET"
end
Rails.application.routes.draw do
devise_for :users
resources :users
end
初始值设定人/designe.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
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
config.omniauth :facebook, "<app_id>", "<app_secret>"
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access'}
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks" }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
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
skip_before_filter :authenticate_user!
def facebook
p env["omniauth.auth"]
user = User.from_omniauth(env["omniauth.auth"])
if user.persisted?
flash[:notice] = "You are in..!!!"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
def failure
#handle you logic here..
#and delegate to super.
super
end
Devise.setup do |config|
config.omniauth :facebook, "KEY", "SECRET"
end
Rails.application.routes.draw do
devise_for :users
resources :users
end
config.omniauth:facebook,“,”
您可以为Omniauth回调创建另一个控制器
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.from_omniauth(request.env['omniauth.auth'])
if @user.persisted?
sign_in_and_redirect @user, :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_user_registration_url
end
end
def after_sign_in_path_for(resource)
super resource
end
end
我记得你不需要在你的member.rb中使用:omniauth\u providers=>[:facebook]
config.omniauth :facebook, "App ID", "App Secret", scope: 'email', info_fields: 'email,name'
现在,您可以在您的注册页面中添加一个按钮
,或者在设计/共享/\u links.html.erb
中包含以下代码,因为它也将在您的登录表单中提供
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign up with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider), class: "btn btn-default navbar-btn" %><br />
<% end -%>
<% end -%>
请阅读这篇最简单的教程,用facebook唱起来。试试这个
config/initializers/designe.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
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
config.omniauth :facebook, "<app_id>", "<app_secret>"
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access'}
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks" }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
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
skip_before_filter :authenticate_user!
def facebook
p env["omniauth.auth"]
user = User.from_omniauth(env["omniauth.auth"])
if user.persisted?
flash[:notice] = "You are in..!!!"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
def failure
#handle you logic here..
#and delegate to super.
super
end
Devise.setup do |config|
config.omniauth :facebook, "KEY", "SECRET"
end
Rails.application.routes.draw do
devise_for :users
resources :users
end
config/routes.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
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
config.omniauth :facebook, "<app_id>", "<app_secret>"
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access'}
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks" }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
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
skip_before_filter :authenticate_user!
def facebook
p env["omniauth.auth"]
user = User.from_omniauth(env["omniauth.auth"])
if user.persisted?
flash[:notice] = "You are in..!!!"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
def failure
#handle you logic here..
#and delegate to super.
super
end
Devise.setup do |config|
config.omniauth :facebook, "KEY", "SECRET"
end
Rails.application.routes.draw do
devise_for :users
resources :users
end
app/models/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
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
config.omniauth :facebook, "<app_id>", "<app_secret>"
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access'}
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks" }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
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
skip_before_filter :authenticate_user!
def facebook
p env["omniauth.auth"]
user = User.from_omniauth(env["omniauth.auth"])
if user.persisted?
flash[:notice] = "You are in..!!!"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
def failure
#handle you logic here..
#and delegate to super.
super
end
Devise.setup do |config|
config.omniauth :facebook, "KEY", "SECRET"
end
Rails.application.routes.draw do
devise_for :users
resources :users
end
app/controllers/omniauth\u callbacks\u controller.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
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
config.omniauth :facebook, "<app_id>", "<app_secret>"
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access'}
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks" }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
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
skip_before_filter :authenticate_user!
def facebook
p env["omniauth.auth"]
user = User.from_omniauth(env["omniauth.auth"])
if user.persisted?
flash[:notice] = "You are in..!!!"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
def failure
#handle you logic here..
#and delegate to super.
super
end
Devise.setup do |config|
config.omniauth :facebook, "KEY", "SECRET"
end
Rails.application.routes.draw do
devise_for :users
resources :users
end
希望这对您有用。Passthru是omniauth的遗物,请更新您的Desive omniauth等宝石。
有一个名为omiauth_callback的控制器,这是一个使noizes;P.(可以帮助您追踪问题的根源)
如果您在控制器中创建了这样的方法:
def直通
结束
您必须创建一个带有(甚至是空的)重定向的视图:受ajax技术的启发,绕过html呈现。
希望它能帮助你解决问题
也可以尝试以下路线:
```
user_omniauth_authorize/users/auth/:provider(:format)sessions#passthru{:provider=>/facebook | twitter | google/}
user_omniauth_callback/users/auth/:action/callback(:format)sessions(?-mix:facebook | twitter | google)
```试试这个:
更新文件:
gem 'omniauth-facebook'
gem 'omniauth'
转到rails\u apps/yourapp/config/initializers/designe.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
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
config.omniauth :facebook, "<app_id>", "<app_secret>"
config.omniauth :facebook, ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], { :scope => 'email, offline_access'}
devise_for :members, controllers: { registrations: 'registrations', omniauth_callbacks: "omniauth_callbacks" }
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
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
skip_before_filter :authenticate_user!
def facebook
p env["omniauth.auth"]
user = User.from_omniauth(env["omniauth.auth"])
if user.persisted?
flash[:notice] = "You are in..!!!"
sign_in_and_redirect(user)
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
def failure
#handle you logic here..
#and delegate to super.
super
end
Devise.setup do |config|
config.omniauth :facebook, "KEY", "SECRET"
end
Rails.application.routes.draw do
devise_for :users
resources :users
end
更新用户模型
class User < ActiveRecord::Base
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|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
end
end
end
在视图中编辑
<%= link_to "Sign in with Facebook", "/auth/facebook", id: "sign_in" %>
请描述一下你试图通过passthru
方法实现什么?@PraveshKhatri我不想用它做任何事情。文档中也没有提到任何关于passthru的内容。我想这是旧版本omniauth的遗物。你确定我需要一个单独的控制器来进行omniauth回调吗?只要路线指向正确的控制器,为什么它在哪个控制器中会有关系?是的,你可以在同一个控制器中进行,但我通常在另一个控制器中进行,因为这让我清楚,如果我需要注册其他社交媒体,如推特、linkedIn等,那么它就不会在我的注册控制器中造成混乱。是的,所以我认为除此之外,我的代码与您发布的代码相同。您认为我们的代码中有什么差异可能导致我的错误?我找不到任何有意义的区别。我刚刚写了“gem'omniauth facebook'”,那是大约一周前的事了,所以我不应该自动拥有最新版本吗?Humm依赖于Gemfile.lock验证此文件,如有必要:gem升级gem_name。顺便说一句:def passthru;渲染:布局=>false;结束``user\u omniauth\u authorize/users/auth/:provider(:format)sessions#passthru{:provider=>/facebook | twitter | google/}user\u omniauth\u callback/users/auth/:action/callback(:format)sessions#(?-mix:facebook | twitter | google)```