What is the use of Destructive Method?
What is the use of Destructive Method?
Here is an explanation of destructive methods in Ruby on Rails:
In Ruby on Rails, destructive methods are those that modify the object they are called on, rather than returning a new object. These methods typically end with an exclamation mark (!) to indicate that they are destructive.
Some common destructive methods in Rails include:
save!
- Saves the record, but raises an ActiveRecord::RecordInvalid
exception if the record is invalid.
destroy!
- Deletes the record from the database and freezes the object, but raises an ActiveRecord::RecordNotDestroyed
exception if the record cannot be deleted.
update!
- Updates the record with the provided attributes, but raises an ActiveRecord::RecordInvalid
exception if the record is invalid.
delete!
- Deletes the record from the database, but raises an ActiveRecord::RecordNotDestroyed
exception if the record cannot be deleted.
reload!
- Reloads the attributes of the object from the database, but raises an ActiveRecord::ActiveRecordError
exception if the object has not been saved.
Destructive methods are useful when you want to ensure tha...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào