ruby-on-rails – OmniAuth不适用于Rails3中的Route Globbing
发布时间:2020-12-17 04:35:08 所属栏目:百科 来源:网络整理
导读:我试图遵循Railscast 241 Simple OmniAuth并且它工作正常,除非我在/config/routes.rb结尾处有Route Globbing: match '*uri' = "posts#index" 如果我使用globbing请求/ auth / twitter,那么OmniAuth什么都不做: Started GET "/auth/twitter" for 127.0.0.1
我试图遵循Railscast 241
Simple OmniAuth并且它工作正常,除非我在/config/routes.rb结尾处有Route Globbing:
match '*uri' => "posts#index" 如果我使用globbing请求/ auth / twitter,那么OmniAuth什么都不做: Started GET "/auth/twitter" for 127.0.0.1 at 2011-04-03 19:17:44 +0200 Processing by PostsController#index as HTML Parameters: {"uri"=>"auth/twitter"} Rendered posts/index.html.haml within layouts/application (9.0ms) Completed 200 OK in 103ms (Views: 14.6ms | ActiveRecord: 0.7ms) 没有通配路线,它可以正确验证. 有没有办法让路线全球化和OmniAuth? 解决方法
The OmniAuth process将在调用/ auth /:提供程序URL时提供以下功能:
>将请求传递给底层的Rack / Rails应用程序,就好像OmniAuth不在那里一样; 由于你基本上使用你的路由通配符匹配所有内容,你的应用程序永远不会给404,OmniAuth无法完成它的工作.我看到两个直接的选择. 手动将OmniAuth路由与404匹配 添加新路线如下: match '/auth/:provider' => 'omniauth#passthru' 然后创建一个生成404的控制器和操作: class OmniauthController < ApplicationController def passthru render :file => "#{Rails.root}/public/404.html",:status => 404,:layout => false end end 确定Glob Route中的404状态 我假设您的glob路线将以某种方式搜索与URL匹配的帖子;你可以抓住失误(例如,当PostsController #index无法找到帖子时)并生成404. class PostsController < ApplicationController def index if @posts = Post.find_by_current_url_or_whatever render 'index' else render :file => "#{Rails.root}/public/404.html",:layout => false end end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |