Override devise registrations controller

前端 未结 5 1728
渐次进展
渐次进展 2020-11-22 00:05

I have added a field to the sign-up form that is based on a different model, see How do I use nested attributes with the devise model for the gory details. This part is work

5条回答
  •  情深已故
    2020-11-22 01:09

    In your form are you passing in any other attributes, via mass assignment that don't belong to your user model, or any of the nested models?

    If so, I believe the ActiveRecord::UnknownAttributeError is triggered in this instance.

    Otherwise, I think you can just create your own controller, by generating something like this:

    # app/controllers/registrations_controller.rb
    class RegistrationsController < Devise::RegistrationsController
      def new
        super
      end
    
      def create
        # add custom create logic here
      end
    
      def update
        super
      end
    end 
    

    And then tell devise to use that controller instead of the default with:

    # app/config/routes.rb
    devise_for :users, :controllers => {:registrations => "registrations"}
    

提交回复
热议问题