Rails3 CMS舒适墨西哥沙发与omniauth的路由不匹配

BBJ*_*BJ3 2 ruby ruby-on-rails omniauth ruby-on-rails-3 comfortable-mexican-sofa

我将舒适的墨西哥沙发CMS与我的Rails 3.0.9应用程序集成在一起,omniauth 0.2.6.

博客方面的一切都很好.我可以登录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):
Run Code Online (Sandbox Code Playgroud)

我的Gemfile.lock在这里:http://pastie.org/2270005

任何帮助将不胜感激.Luca G. Soave

BBJ*_*BJ3 5

这是一个路由问题.

Omniauth通过检测404错误页面来工作:

如果它匹配route/auth /:provider,则它捕获请求将其发送给提供者

...但舒适的墨西哥沙发cms(如炼油厂和其他),有一个捕获所有路线,这就是为什么请求永远不会返回404错误,omniauth可以检测到.

在舒适的墨西哥沙发盒中,它经历了"cms_path"=>"auth/github"获得

NoMethodError in CmsContentController#render_html
undefined method `gsub!' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)

而不是正确的omniauth路径应该如下:

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)
Run Code Online (Sandbox Code Playgroud)

我的解决方案如下:

在app/controllers/errors_controller.rb中

class ErrorsController < ApplicationController
  def error
    render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
  end
end
Run Code Online (Sandbox Code Playgroud)

在config/routes.rb中添加在底部

match '/auth/:provider' => 'errors#error'

...在Omniouth最后一条路线之后

`match "/auth/:provider/callback" => "sessions#create"`
Run Code Online (Sandbox Code Playgroud)

谢谢你Federico GonzalezOleg Khabarov

我希望这会帮助别人;-)

再见Luca G. Soave