参考:https://stackoverflow.com/questions/5056385/when-to-use-save-vs-save-in-model

https://apidock.com/rails/ActiveRecord/Base/save%21

https://apidock.com/rails/v5.2.3/ActiveRecord/Persistence/save

# frozen_string_literal: true

class Accounts::RegistrationsController < Devise::RegistrationsController
  layout 'front_ends'
  # before_action :configure_sign_up_params, only: [:create]
  # before_action :configure_account_update_params, only: [:update]

  # GET /resource/sign_up
  def new
    super
  end

  # POST /resource
  def create
  #  super
    #Account.create email: params[:email], mobile: params[:mobile], password: params[:password]
    account = Account.new
    account.mobile = params[:mobile]
    account.email = "need_to_bind_#{account.mobile}@email.com"
    account.password= params[:password]
    account.save!
    redirect_to '/', notice: 'operation success'
  end

在devise不能直接使用create,需要进行new+save!

<strong>save!</strong>()
public

Saves the model.

If the model is new a record gets created in the database, otherwise the existing record gets updated.

With save! validations always run. If any of them fail ActiveRecord::RecordInvalid gets raised. See ActiveRecord::Validations for more information.

There’s a series of callbacks associated with save!. If any of the before_* callbacks return false the action is cancelled and save! raises ActiveRecord::RecordNotSaved. See ActiveRecord::Callbacks for further details.

 

<strong>save</strong>(*args, &amp;block)
public

Saves the model.

If the model is new, a record gets created in the database, otherwise the existing record gets updated.

By default, save always runs validations. If any of them fail the action is cancelled and #save returns false, and the record won’t be saved. However, if you supply validate: false, validations are bypassed altogether. See ActiveRecord::Validations for more information.

By default, #save also sets the updated_at/updated_on attributes to the current time. However, if you supply touch: false, these timestamps will not be updated.

There’s a series of callbacks associated with #save. If any of the before_* callbacks throws :abort the action is cancelled and #save returns false. See ActiveRecord::Callbacks for further details.

Attributes marked as readonly are silently ignored if the record is being updated.