2013-02-20 89 views
0

我跟隨Railscast http://railscasts.com/episodes/235-devise-and-omniauth-revised?view=comments關於實現omniauth成devise,特別是添加Twitter登錄。當我添加簽署鏈接到Twitter上我的應用程序,我得到這個錯誤訪問首頁rake路由說路由存在,但錯誤消息說不然

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

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

如果我做耙路線(見下文),它表明我有「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 

回答

0

的錯誤是,我經過:供應商,而不是:Twitter的作爲鏈接的參數。

錯誤

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

正確:

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