【问题标题】:Rails3 CMS comfortable-mexican-sofa get mismatching routing with omniauthRails3 CMS 舒适墨西哥沙发获得与omniauth 不匹配的路由
【发布时间】:2011-07-25 19:36:41
【问题描述】:

我将 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):

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

任何帮助将不胜感激。 卢卡·G·索阿夫

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 omniauth comfortable-mexican-sofa


    【解决方案1】:

    这是一个路由问题。

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

    如果它匹配路由 /auth/:provider,那么它会捕获请求并将其发送给提供者

    ...但是comfortable-mexican-sofa cms(如refinery 和其他人)有一条捕获所有路由,这就是为什么请求从未返回 404 错误,omniauth 可以检测到。

    在舒适墨西哥沙发的情况下,它通过"cms_path"=>"auth/github"得到

    NoMethodError in CmsContentController#render_html
    undefined method `gsub!' for nil:NilClass
    

    而不是正确的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)
    

    我的解决方案如下:

    在 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' =&gt; 'errors#error'

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

    `match "/auth/:provider/callback" => "sessions#create"`
    

    感谢Federico Gonzalez 和Oleg Khabarov

    我希望这对其他人有帮助;-)

    再见 Luca G. Soave

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多