在嵌套路由下设计用户

时间:2013-12-26 22:04:06

标签: ruby-on-rails devise

我有一个名为“Store”的资源,可以注册许多帐户,但我应该如何使用设备执行此操作?我已经设置了这个

class Store
  has_many :accounts
end

class Account
  belongs_to :store
end

Panel::Application.routes.draw do
  resources :stores do
    devise_for :accounts
  end
end

但即将到来

Showing panel/app/views/accounts/registrations/new.html.haml where line #2 raised:
undefined method `account_registration_path' for #<Module:0x007f9a67940918>

这是bc,它期待像“account_store_registration_path”这样的东西但所有这些逻辑都在哪里

rake路线输出

account_store_password POST   /accounts/stores/:store_id/password(.:format)                                 devise/passwords#create
         new_account_store_password GET    /accounts/stores/:store_id/password/new(.:format)                             devise/passwords#new
        edit_account_store_password GET    /accounts/stores/:store_id/password/edit(.:format)                            devise/passwords#edit
                                     PATCH  /accounts/stores/:store_id/password(.:format)                                 devise/passwords#update
                                     PUT    /accounts/stores/:store_id/password(.:format)                                 devise/passwords#update
  cancel_account_store_registration GET    /accounts/stores/:store_id/cancel(.:format)                                   devise/registrations#cancel
         account_store_registration POST   /accounts/stores/:store_id(.:format)                                          devise/registrations#create
     new_account_store_registration GET    /accounts/stores/:store_id/sign_up(.:format)                                  devise/registrations#new
    edit_account_store_registration GET    /accounts/stores/:store_id/edit(.:format)                                     devise/registrations#edit
                                     PATCH  /accounts/stores/:store_id(.:format)                                          devise/registrations#update
                                     PUT    /accounts/stores/:store_id(.:format)                                          devise/registrations#update
                                     DELETE /accounts/stores/:store_id(.:format)                                          devise/registrations#destroy
         account_store_confirmation POST   /accounts/stores/:store_id/confirmation(.:format)                             devise/confirmations#create
     new_account_store_confirmation GET    /accounts/stores/:store_id/confirmation/new(.:format)                         devise/confirmations#new
                                     GET    /accounts/stores/:store_id/confirmation(.:format)                             devise/confirmations#show

1 个答案:

答案 0 :(得分:0)

所以要做到这一点,我做了一件非常简单的事情

我为该帐户定义了另一条路线:

Panel::Application.routes.draw do
  devise_for :accounts

  resources :stores do
    resources :accounts
  end
end

我生成了一个帐户控制器和视图,并使用了Devise生成的模型。所以我使用新的控制器创建帐户和设计帮助程序来管理登录逻辑。

所以现在我可以拥有属于商店的帐户