Difference between create & save in RoR?

The create method creates a record or a set of records in the database if the validations are successful and it resturns a status whether the object has been saved into the database successfully or not.

Save method checks whether the record exists if exists it updates the existing record otherwise it will create a new record and checks for the validation by default. If there are any callbacks available it will execute upon the successful. If we want to stop performing validations while creating an object then you need to pass perform_validation=false as argument to the save method.

No comments:

Post a Comment