We have a User model, also worth Devise . At the user except standard fields, I added first_name and last_name . These fields made mandatory by the user. The question is how to register new users through the standard device page without adding the first and last name fields? How to make it possible to fill in this data after registration?

    2 answers 2

    Run rails g devise:views . Devise will generate views into your project, and after that you can do whatever you want with them.

    UPD:

    In English, SO is advised to act in such a way that only one attribute is checked for validity:

    In the User model, write the method:

     def valid_attribute?(attribute_name) self.valid? self.errors[attribute_name].blank? end 

    Then in the UsersController controller:

     def create @user = User.new(email: user_params[:email], password: user_params[:password], password_confirmation: user_params[:password_confirmation]) if @user.valid_attribute?(:email) @user.save(validate: false) redirect_to '<такой-то адрес>' else render :new end end 
    • I asked a little more :) how to root a user and not enter first_name and last_name, although these fields are mandatory - Alex I
    • one
      @AlexanderIvanov added - MAXOPKA
    • exactly! thanks - Alex I

    Try this (in the User model):

     validates :first_name, :last_name, presence: true, on: :update