【问题标题】:Rails 4 Devise + Omniauth Github Routing ErrorRails 4 Devise + Omniauth Github 路由错误
【发布时间】:2014-09-25 13:22:31
【问题描述】:

我正在使用 Rails 4.1.1,我正在尝试在我的应用程序中使用我的 devise gem 创建omniauth github。但是我遇到了路由错误,我正在关注 Railscast #235 关于这个主题的修订。

现在,我正在尝试做 Ryan Bates 正在做的同样的事情,即将 omniauth.auth 作为 yaml 提升到屏幕上,但我得到了错误:

No route matches [GET] "/auth/github/callback"

如何解决这个错误?

这里有我的路线:

Rails.application.routes.draw do
  devise_for :users, controllers: {omniauth_callbacks: "omniauth_callbacks"}

  root to: 'questions#index'

  resources :questions do
    resources :answers, only: [:create]
  end

  resources :users, only: [:show]

  #USERS CONTROLLER MY ROUTES
  get "adding_likes/(:id)/(:like)/(:current_user_id)", to: "answers#adding_likes", as: :adding_likes
  get "add_accept/(:answer_id)", to: "answers#accept", as: :accept
  get "leaderboard", to: "users#leaderboard", as: :leaderboard
end

我的控制器:

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def all
    raise request.env["omniauth.auth"].to_yaml
  end
  alias_method :github, :all
end

我的用户模型:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :omniauthable
  # :recoverable, :rememberable and :trackable
  devise :database_authenticatable, :registerable, :validatable, :omniauthable
  has_attached_file :avatar, :styles => { :small => "100x100>" }
  validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/

  # has_attached_file :superstarbadge, :styles => { :small => "100x100>" } 
  # validates_attachment_content_type :superstarbadge, :content_type => /\Aimage\/.*\Z/

  has_many :questions
  has_many :answers

  def to_s
    email
  end
end

我的 devise.rb 的重要部分

config.omniauth :github,NOT-VISIBILE,IN-HERE

【问题讨论】:

    标签: ruby-on-rails-4 devise omniauth


    【解决方案1】:

    基本上,您还没有为其添加路线。我认为您错过了 Ryan 将其添加到他的路线文件中。只需添加以下内容:

    get "/auth/github/callback" => "yourController#yourAction"
    

    但是由于您使用的是omniauth,所以这种方式更好

    get "/auth/:provider/callback" => "yourController#yourAction
    

    并为其添加必要的视图。

    【讨论】:

      猜你喜欢
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 2015-11-03
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 2016-02-26
      相关资源
      最近更新 更多