Rails3 CMS快適なメキシカンソファは、Omniauthを使用してルーティングを不一致にします
-
26-10-2019 - |
質問
統合しました 快適なメキシカソファCMS Omniauth 0.2.6を搭載したRails 3.0.9アプリを使用して。
すべてがうまく機能しますブログ側。 CMS Adminをログインして、管理コンソールを使用して投稿してログオフします(CMS-Adminには、アプリとは異なる独自の認証システムがあります...)新しい投稿を閲覧することができます。
問題は、私のアプリの残りの部分がOmniauthでユーザーを認証し、ログオフ/オンになったときに次のエラーが発生したことです。
Started GET "/auth/github" for 127.0.0.1 at 2011-07-25 21:04:46 +0200
Processing by CmsContentController#render_html as HTML
Parameters: {"cms_path"=>"auth/github"}
SQL (0.3ms) SELECT COUNT(*) FROM "cms_sites"
Cms::Site Load (0.3ms) SELECT "cms_sites".* FROM "cms_sites" LIMIT 1
Completed 500 Internal Server Error in 156ms
NoMethodError (undefined method `gsub!' for nil:NilClass):
私のgemfile.lockはここにあります: http://pastie.org/2270005
どんな助けも大歓迎です。 Luca G. Soave
解決
それはルーティングの問題でした。
Omniauthは、404エラーページを検出することで機能します。
ルート /auth /:プロバイダーに一致する場合、リクエストをキャッチします。プロバイダーに送信します
... しかし 快適なメキシカソファCMS (お気に入り 製油所 その他)、すべてのルートがあります。そのため、リクエストが404エラーを返さず、Omniauthが検出できます。
快適なメキシカソファの場合、それは通過します "cms_path"=>"auth/github"
取得
NoMethodError in CmsContentController#render_html
undefined method `gsub!' for nil:NilClass
次のようになるはずの正しいオムニアースパスの代わりに:
Started GET "/" for 127.0.0.1 at 2011-07-25 22:27:26 +0200
Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (29.5ms)
Completed 200 OK in 44ms (Views: 42.8ms | ActiveRecord: 0.0ms)
Started GET "/auth/github" for 127.0.0.1 at 2011-07-25 22:27:35 +0200
MONGODB gitwatch_dev['users'].find({:provider=>"github", :uid=>1573})
Started GET "/auth/github/callback?code=4334bab983hd5fec19dd" for 127.0.0.1 at 2011-07-25 22:27:36 +0200
Processing by SessionsController#create as HTML
Parameters: {"code"=>"4334bab983hd5fec19dd", "provider"=>"github"}
Redirected to http://localhost:3001/
Completed 302 Found in 255ms
MONGODB gitwatch_dev['users'].find({:_id=>BSON::ObjectId('4e23114b1d41c80f180005b2')})
Started GET "/" for 127.0.0.1 at 2011-07-25 22:27:39 +0200
Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (415.6ms)
Completed 200 OK in 890ms (Views: 428.6ms | ActiveRecord: 0.0ms)
私の場合の解決策は、次のようなものです。
APP/Controllers/errors_controller.rbで
class ErrorsController < ApplicationController
def error
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
config/routes.rb下部に追加します
match '/auth/:provider' => 'errors#error'
...オムニウスの最後のルートの後
`match "/auth/:provider/callback" => "sessions#create"`
ありがとう Federico Gonzalez
とに オレグ・ハバロフ
私はこれが他の誰かを助けることを願っています;-)
さようならルカ・G・ソーヴ