0

I am using Devise and when I check the form for registration of the new user, in the method is set up just this: /users.

When I check in logs where the app goes after hitting submit button in the registration form, it's here:

Started POST "/users" for 127.0.0.1 at 2013-08-21 18:13:11 +0200
Processing by Devise::RegistrationsController#create as HTML

But when I go to the Registration Controller and there to the action create and comment all code in there, there is no error, everything is processed correctly, which makes me confused.

Where is the code for creating a new user for Devise gem?

4

1 回答 1

1

您的自定义 RegistrationController 是为在需要时覆盖原始的而构建的。

如果您删除所有自定义代码,则会调用 gem 中的原始控制器。加载时它已经包含在应用程序中。

这是原始代码:https ://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb

要正确覆盖,您需要在 routes.rb 中指定它。

  devise_for :users, :controllers => { registrations: 'users/registrations',
                                   sessions: 'users/sessions' }

然后,创建文件app/controllers/users/registrations_controller.rb.

然后,用路由中定义的命名空间命名这个类,并从原始控制器继承它

class Users::RegistrationController < Devise::RegistrationsController
  def create
    if foo == bar
      # your logic
    else
      super # Call original method
    end
  end
end
于 2013-08-21T16:19:17.743 回答