我一直在這一個拉我的頭髮幾個小時...我有一個Devise和omniauth設置,允許用戶使用他們的Facebook帳戶登錄。我使用下面的寶石版本:Heroku的Devise + omniauth路由問題
Installing devise (1.4.7)
Installing oauth2 (0.4.1)
Installing oa-oauth (0.2.6)
Installing omniauth (0.2.6)
等等,並在我的設計初始化應用程序ID和祕密:
config.omniauth :facebook, 'app_id', 'app_secret',
{:scope => 'email, offline_access', :client_options => {:ssl => {:verify => false}}}
雖然我也試過這個沒有運氣:
config.omniauth :facebook, 'app_id', 'app_secret',
# {:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
我在我的用戶模型中有:omniauthable指令,並且我在路由文件中定義了我自己的回調控制器:
devise_for :users, :controllers => { :omniauth_callbacks => 'user/authentications', :registrations => 'registrations' }
root :to => 'pages#home'
而且我也嘗試添加這對路由文件,沒有運氣:
get '/users/auth/:provider' => 'user/authentications#passthru'
這裏是我的認證控制器:
class AuthenticationsController < Devise::OmniauthCallbacksController
def index
@authentications = current_user.authentications if current_user
end
def facebook
omniauth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, authentication.user)
elsif current_user
current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
else
user = User.new
user.apply_omniauth(omniauth)
if user.save
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, user)
else
session[:omniauth] = omniauth.except('extra')
redirect_to new_user_registration_url
end
end
end
def passthru
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
def destroy
@authentication = current_user.authentications.find(params[:id])
@authentication.destroy
flash[:notice] = "Successfully destroyed authentication."
redirect_to authentications_url
end
end
我的Facebook帳號登錄鏈接:
< %= link_to image_tag('/ assets/facebook_32.png'),omniauth_authorize_path(resource_name,:facebook)%>
這一切的偉大工程在當地,但如果我嘗試當我的應用程序部署到Heroku上與我的Facebook帳戶登錄,我得到了我的日誌下面,我引導到404頁:
2011-09-23T03:26:31+00:00 app[web.1]: ActionController::RoutingError (uninitiali
zed constant User::AuthenticationsController):
我試着重置我的數據庫,但這也沒有幫助。
這裏是我的路線從Heroku的:
new_user_session GET /users/sign_in(.:format) {:action=
>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=
>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=
>"destroy", :controller=>"devise/sessions"}
user_omniauth_callback /users/auth/:action/callback(.:format) {:action=
>/facebook/, :controller=>"user/authentications"}
user_password POST /users/password(.:format) {:action=
>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=
>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=
>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=
>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=
>"cancel", :controller=>"registrations"}
user_registration POST /users(.:format) {:action=
>"create", :controller=>"registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=
>"new", :controller=>"registrations"}
edit_user_registration GET /users/edit(.:format) {:action=
>"edit", :controller=>"registrations"}
PUT /users(.:format) {:action=
>"update", :controller=>"registrations"}
DELETE /users(.:format) {:action=
>"destroy", :controller=>"registrations"}
root / {:control
ler=>"pages", :action=>"home"}
任何幫助是極大的讚賞。如果您需要其他信息,請告訴我。我知道這很小,但我覺得我已經嘗試了一千種不同的東西,沒有任何工作。
是不是您的「passthru」行動呈現404.html。如果你在做'/ users/auth /:provider'=>'user/authentications#passthru' –
這是,但我目前沒有使用它。 –