Câu hỏi phỏng vấn Ruby on Rails
Câu hỏi

What Is The Difference Between Delete And Destroy ?

Câu trả lời

Here is an explanation of the difference between the delete and destroy methods in Ruby on Rails:

delete vs destroy

In Ruby on Rails, both delete and destroy are methods used to remove records from the database, but they differ in their behavior and consequences:

delete

  • The delete method removes a record from the database without executing any callbacks.
  • It is faster than destroy because it skips the callback chain.
  • delete does not trigger the before_destroy and after_destroy callbacks.
  • It is useful when you want to remove records quickly without executing any additional logic.
  • Example: User.delete(1) or User.where(email: 'example@example.com').delete_all...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

Explain what is Polymorphic Association in Ruby on Rails?

middle

Can you explain the difference between ActiveSupport’s HashWithIndifferentAccess and Ruby’s Hash ?

junior

What Do You Mean By Render And Redirect_to ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào