Ruby on rails OmniAuth操作控制器错误
我在Rails应用程序中使用OmniAuth gem,允许用户将他们的Facebook帐户添加到应用程序中,我遵循Ryan Bates的教程,但我仍然会遇到这个Rails错误 未定义的局部变量或方法“authentications\u url”# 以下是用于身份验证的控制器:Ruby on rails OmniAuth操作控制器错误,ruby-on-rails,ruby,omniauth,Ruby On Rails,Ruby,Omniauth,我在Rails应用程序中使用OmniAuth gem,允许用户将他们的Facebook帐户添加到应用程序中,我遵循Ryan Bates的教程,但我仍然会遇到这个Rails错误 未定义的局部变量或方法“authentications\u url”# 以下是用于身份验证的控制器: class AuthenticationsController < ApplicationController def index @authentications = current_
class AuthenticationsController < ApplicationController
def index
@authentications = current_user.authentications if current_user
end
def create
auth = request.env["omniauth.auth"]
current_user.authentications.find_or_create_by_provider_and_uid(auth['provider'],auth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
end
def destroy
@authentication = current_user.authentications.find(params[:id])
@authentication.destroy
flash[:notice] = "Successfully destroyed authentication."
redirect_to authentications_url
end
类身份验证控制器
结束您的错误告诉您您的路线不存在。在命令提示下运行
rake routes
,查看是否有authentications
路由
从该集的版本来看,您的config/routes.rb
文件应该类似于以下内容:
ProjectManage::Application.routes.draw do |map|
match '/auth/:provider/callback' => 'authentications#create'
devise_for :users
resources :projects
resources :tasks
resources :authentications # <-- This is the one you're missing
root :to => 'projects#index'
end
ProjectManage::Application.routes.draw do | map |
匹配'/auth/:提供程序/回调'=>'身份验证#创建'
为:用户设计
资源:项目
资源:任务
资源:认证#谢谢!这对我帮助很大。很高兴听到这个消息,如果答案回答了你的问题,请勾选复选标记接受答案