Rails - 设计 - 向控制器添加动作

时间:2013-11-12 22:17:58

标签: ruby-on-rails devise controller

我在设计控制器中添加动作时遇到了一些麻烦。 我在文件夹registrations_controller中创建了一个名为users/的控制器,如下所示:

class Users::RegistrationsController < Devise::RegistrationsController

而且,有我的路线档案:

root to: 'home#index'

devise_for :users
devise_scope :users do
    get 'users/profil/:id', to: 'users/registrations#profil', as: 'profil'
end

我看到以下错误:

Unknown action
Could not find devise mapping for path "/users/profil/1"
This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router.

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:5)

尝试以下方法:

    devise_scope :user do
       get 'users/profil/:id', to: 'users/registrations#profil', as: 'profil'
    end
    devise_for :users, :controllers => {:registrations => "users/registrations"}
    resources :users 

此外,您无需为控制器Users::RegistrationsController命名,并将其命名为RegistrationController,保留继承,因为Devise::RegistrationsController