0

我正在关注 Railscast http://railscasts.com/episodes/235-devise-and-omniauth-revised?view=comments关于在设计中实现omniauth,特别是添加Twitter 登录。当我将登录 Twitter 的链接添加到我的应用程序时,我在访问主页时收到此错误

  <li><%= link_to "Sign In With Twitter", user_omniauth_authorize_path(:provider) %></li>

No route matches {:controller=>"omniauth_callbacks", :action=>"passthru", :provider=>:provider}

如果我做 rake 路由(见下文),它表明我有 'user_omniauth_callback' 路由,但它没有指定请求类型(GET、POST)等,我不确定这是否重要。

我在 SO 上搜索了这个错误,一个人遇到了类似的问题,原因是没有在 routes.rb 中包含以下代码,但我已经包含了。

devise_for :users, path_names: {sign_in: "login", sign_out: "logout"},
                   controllers: {omniauth_callbacks: "omniauth_callbacks"}

在他添加omniauth控制器的情节部分之前出现了错误;我添加它只是为了确定,但我仍然遇到同样的错误:

class OmniauthCallbacksController < Devise::OmniauthCallbacksController

    def all
        request.env["omniauth.auth"]

    end

    alias_method :twitter, :all
end

我不确定我还能看到什么。在设计初始化程序中,我为 Twitter 设置了配置

config.omniauth :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"]

这是我的用户模型

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :omniauthable,
         :recoverable, :rememberable, :trackable, :validatable


  attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :image, :provider, :uid

  validates_uniqueness_of :name, :email, :case_sensitive => false
end

你能就我可以做些什么来解决这个问题提出任何建议吗?

耙子路线

 new_user_session GET    /users/sign_in(.:format)               devise/sessions#new
            user_session POST   /users/sign_in(.:format)               devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)              devise/sessions#destroy
 user_omniauth_authorize        /users/auth/:provider(.:format)        devise/omniauth_callbacks#passthru {:provider=>/twitter/}
  user_omniauth_callback        /users/auth/:action/callback(.:format) devise/omniauth_callbacks#(?-mix:twitter)
           user_password POST   /users/password(.:format)              devise/passwords#create
       new_user_password GET    /users/password/new(.:format)          devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)         devise/passwords#edit
                         PUT    /users/password(.:format)              devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                devise/registrations#cancel
       user_registration POST   /users(.:format)                       devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)               devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                  devise/registrations#edit
                         PUT    /users(.:format)                       devise/registrations#update
                         DELETE /users(.:format)                       devise/registrations#destroy
4

1 回答 1

0

错误是我传递 :provider 而不是 :twitter 作为链接中的参数。

不正确

<%= link_to "Sign In With Twitter", user_omniauth_authorize_path(:provider) %>

正确的:

 <%= link_to "Sign In With Twitter", user_omniauth_authorize_path(:twitter) %>
于 2013-02-20T22:02:41.383 回答