rails3设计omniauth twitter配置

时间:2012-02-21 15:08:00

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

当我尝试到达http://127.0.0.1:3000/auth/twitter时,我收到以下错误:

Routing Error
No route matches [GET] "/auth/twitter

但我可以通过 - “/ users / auth / twitter /”来访问它,但后来我的回调路径错误。

如何让Twitter使用正确的网址 - “/ auth / twitter”?下面,我发布了我的应用程序文件。我使用Rails3,Devise,Omniauth

这是rake路线输出:

$ rake routes
         authentications GET    /authentications(.:format)             authentications#index
                         POST   /authentications(.:format)             authentications#create
      new_authentication GET    /authentications/new(.:format)         authentications#new
     edit_authentication GET    /authentications/:id/edit(.:format)    authentications#edit
          authentication GET    /authentications/:id(.:format)         authentications#show
                         PUT    /authentications/:id(.:format)         authentications#update
                         DELETE /authentications/:id(.:format)         authentications#destroy
              home_index GET    /home/index(.:format)                  home#index
        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_callback        /users/auth/:action/callback(.:format) devise/omniauth_callbacks#(?-mix:(?!))
           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
       user_confirmation POST   /users/confirmation(.:format)          devise/confirmations#create
   new_user_confirmation GET    /users/confirmation/new(.:format)      devise/confirmations#new
                         GET    /users/confirmation(.:format)          devise/confirmations#show
                   users GET    /users(.:format)                       users#index
                         POST   /users(.:format)                       users#create
                new_user GET    /users/new(.:format)                   users#new
               edit_user GET    /users/:id/edit(.:format)              users#edit
                    user GET    /users/:id(.:format)                   users#show
                         PUT    /users/:id(.:format)                   users#update
                         DELETE /users/:id(.:format)                   users#destroy
                                /auth/:provider/callback(.:format)     authentications#create
                    root        /       

                           home#index

我的omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, '****', '****'
end

的Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.1'

gem 'mysql2'
gem 'devise'
gem 'cancan'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'nifty-generators'

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

gem "mocha", :group => :test

的routes.rb

RaritySoft::Application.routes.draw do

  resources :authentications

  get "home/index"

  devise_for :users
  resources :users

  match '/auth/:provider/callback' => 'authentications#create'

  root :to => 'home#index'
end

User.rb

class User < ActiveRecord::Base

  has_many :authentications

  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end

1 个答案:

答案 0 :(得分:4)

我已删除:omniauthable,现在一切正常