gpt4 book ai didi

ruby-on-rails - rails3 devise omniauth 推特配置

转载 作者:太空宇宙 更新时间:2023-11-03 17:58:26 25 4
gpt4 key购买 nike

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

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

但我可以通过 - "/users/auth/twitter/"访问它,但我有一个错误的回调路径。

如何使用正确的 url - "/auth/twitter"获得 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

gem 文件:

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

路线.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

用户.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

最佳答案

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

关于ruby-on-rails - rails3 devise omniauth 推特配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9379881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com