Rails 4 Devise + Omniauth Github路由错误

时间:2014-08-02 13:22:07

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

我正在使用Rails 4.1.1,并且我试图在我的应用程序中使用我的设计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

1 个答案:

答案 0 :(得分:0)

基本上,您还没有添加路线。我想你已经错过了Ryan将它添加到他的路线文件中。只需添加:

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

但是既然你正在使用omniauth,那就更好了

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

并为其添加必要的视图。