【发布时间】: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