Profile model for Devise users?

前端 未结 5 1040
青春惊慌失措
青春惊慌失措 2020-11-28 02:13

I want to extend the sign up form of my devise installation. I created a Profile model and am asking myself now, how can I add specific data of the form to this model. Where

5条回答
  •  难免孤独
    2020-11-28 02:28

    To complement mbreining's answer, in Rails 4.x you'll need to use strong parameters to allow nested attributes to be stored. Create a registration controller subclass:

    RegistrationsController < Devise::RegistrationsController
    
      def sign_up_params
        devise_parameter_sanitizer.sanitize(:sign_up)
        params.require(:user).permit(:email, :password, profile_attributes: [:first_name, :last_name])
      end
    end
    

提交回复
热议问题