设计omniauth范围以将用户添加到业务

时间:2016-08-23 02:03:41

标签: ruby-on-rails devise

我已经设计好了,我希望用户能够像这样登录/注册:

http://awesomesite.com/businessName/users/sign_in

如果他们在businessName路线上注册,我想让它们自动添加为业务权利的用户。

我有omniauth,我知道omniauth无法处理动态作用域,并且需要明确设置omniauth的路由,因为我收到了这个错误:

Devise does not support scoping omniauth callbacks under a dynamic segment (RuntimeError)
 You can work around by passing
 `skip: :omniauth_callbacks` and manually defining the routes. Here is an example:

match "/users/auth/:provider",
  constraints: { provider: /google|facebook/ },
  to: "devise/omniauth_callbacks#passthru",
  as: :omniauth_authorize,
  via: [:get, :post]

match "/users/auth/:action/callback",
  constraints: { action: /google|facebook/ },
  to: "devise/omniauth_callbacks",
  as: :omniauth_callback,
  via: [:get, :post]

我做了一些研究并想出了这条路线设置:

  scope '(:business)', locale: /acmecorp/ do
      devise_for :users, skip: [:invitation, :registration, :confirmation, :omniauth_callbacks], controllers: { :sessions => "devise/sessions", :registrations => "devise/registrations" }
      match "/users/auth/:provider",
        constraints: { provider: /google|facebook/ },
        to: "users/omniauth_callbacks#passthru",
        as: :omniauth_authorize,
        via: [:get, :post]

      match "/users/auth/:action/callback",
        constraints: { action: /google|facebook/ },
        to: "users/omniauth_callbacks",
        as: :omniauth_callback,
        via: [:get, :post]
  end

但是我收到了这个错误:

undefined method `user_omniauth_authorize_path' for #<#<Class:0x007fc1214f1fe8>:0x007fc11cf711d0>

当我尝试访问http://awesomesite/acmecorp/users/sign_in

我试着看看设计维基和stackoverflow,但它并没有点击给我。

编辑:运行rake路线为我提供相关路线:

                             Prefix Verb     URI Pattern                                                                       Controller#Action
                   new_user_session GET      (/:business)/users/sign_in(.:format)                                              devise/sessions#new
                       user_session POST     (/:business)/users/sign_in(.:format)                                              devise/sessions#create
               destroy_user_session DELETE   (/:business)/users/sign_out(.:format)                                             devise/sessions#destroy
                      user_password POST     (/:business)/users/password(.:format)                                             devise/passwords#create
                  new_user_password GET      (/:business)/users/password/new(.:format)                                         devise/passwords#new
                 edit_user_password GET      (/:business)/users/password/edit(.:format)                                        devise/passwords#edit
                                    PATCH    (/:business)/users/password(.:format)                                             devise/passwords#update
                                    PUT      (/:business)/users/password(.:format)                                             devise/passwords#update
                 omniauth_authorize GET|POST (/:business)/users/auth/:provider(.:format)                                       users/omniauth_callbacks#passthru {:provider=>/google|facebook/}
                  omniauth_callback GET|POST (/:business)/users/auth/:action/callback(.:format)                                users/omniauth_callbacks#(?-mix:google|facebook)

0 个答案:

没有答案