Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
117 views
in Technique[技术] by (71.8m points)

ruby on rails - Destruction of records in around_update

Before updating the record, I need to do some checks. As a result of one of the checks, I need to destroy the record that is being updated.

I have two questions.

  1. How good is this solution? (I need to delete a record on update because a similar record was found among the old ones)

  2. What is the correct way to implement cancellation of an update after a record has been destroyed?

I wrote this simple code:

return yield unless title_changed?

tmp_destroyed = false

# some code

tmp_destroyed = true if destroy!

# some code

return if tmp_destroyed

yield

But I'm not sure if this is the right decision.

Can you please tell me if I'm doing everything right? And did I choose the right way for the solution?

question from:https://stackoverflow.com/questions/65919616/destruction-of-records-in-around-update

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would suggest, before updating the record, check your conditions in controller and if your conditions is true then delete the record instead of checking in model callback methods.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...