【问题标题】:OmniAuth Action Controller ErrorOmniAuth 动作控制器错误
【发布时间】:2011-10-12 01:11:36
【问题描述】:

我将 OmniAuth gem 与我的 Rails 应用程序一起使用,以允许用户将他们的 Facebook 帐户添加到应用程序,并且我正在关注 Ryan Bates 的教程,但我继续收到此 Rails 错误。

用于#的未定义局部变量或方法`authentications_url'

这是用于身份验证的控制器:

    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

结束

【问题讨论】:

    标签: ruby-on-rails ruby omniauth


    【解决方案1】:

    您的错误是告诉您您的路线不存在。在命令提示符下运行rake routes,看看是否有authentications 路由

    从该剧集的ASCIIcasts 版本中,您的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 
    

    【讨论】:

    • 谢谢!这对我帮助很大。
    • 很高兴听到它,如果它回答了您的问题,请勾选复选标记接受答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多