`
Hooopo
  • 浏览: 335258 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

check-if-record-was-just-destroyed-in-rails

阅读更多

问题:

So there is

record.new_record?

To check if something is new

I need to check if something is on it's way out.

record = some_magic
record.destroy
record.is_destroyed? # => true

Something like that. I know destroying freezes the object, so frozen? sort of works, but is there something explicitly for this task?

回答:

1.You can do this.

Record.exists?(record)

However that will do a hit on the database which isn't really necessary. The only other solution I know is to do a callback as theIV mentioned.

attr_accessor :destroyed
after_destroy :mark_as_destroyed
def mark_as_destroyed
  self.destroyed = true
end

And then check record.destroyed.

 

2.This is coming very soon. In the latest Riding Rails post, it says this:

And finally, it's not necessarily BugMash-related, but José Valim - among dozens of other commits - added model.destroyed?. This nifty method will return true only if the instance you're currently looking at has been successfully destroyed.

So there you go. Coming soon!

http://stackoverflow.com/questions/1297111/check-if-record-was-just-destroyed-in-rails

 

分享到:
评论

相关推荐

    operation-destroyed-pony-web

    在IT行业中,"operation-destroyed-pony-web"这个标题可能是指一个针对特定网站,名为"小马网"的模拟或演练操作,目的是演示如何安全地销毁或退役一个网站。这种操作通常涉及到一系列复杂的步骤,包括数据备份、系统...

    ruby-destroyed_at, 用于安全销毁的ActiveRecord Mixin.zip

    ruby-destroyed_at, 用于安全销毁的ActiveRecord Mixin DestroyedAt 查找帮助?如果是一个 Bug ,请在GitHub上打开一个问题。安装将 destroyed_at gem 添加到 Gemfilegem 'destroyed_at'你可以在每个模块中

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: If the TCustomProp.Assign method calls when the undo/redo history writing was in progress, the error occured. - FIX: The TFlexPanel.LoadFlexControl method now virtual. - FIX: The TFlexPanel....

    occam一维反演

    WITH STATIC COMMONS (CHECK YOU COMPILER!) THESE NEED NOT BE DECLARED C IN THE CALLING PROGRAMS. INPUTM IS ALSO RESPONSIBLE FOR SETTING ANY C MODEL PREJUDICE IN /RESULT/ PREMOD(), ALTHOUGH THIS ...

    35 道必看的 Vue 面试题-( 前端开发 + Vue + 面试题 + 准备)

    Vue实例从创建到销毁经历多个阶段,如beforeCreate、created、beforeMount、mounted、beforeUpdate、updated、beforeDestroy和destroyed。在不同阶段,可以执行特定任务,例如初始化数据、操作DOM、响应式更新等。 ...

    Vue 35 道面试题及答案.docx

    本文主要讲解了 Vue.js 框架中的 MVVM 模式、生命周期、v-if 和 v-show 的区别、v-if 和 v-for 的使用、key 的理解、transition 的理解等知识点。 MVVM 模式 MVVM 模式是 Model-View-ViewModel 的缩写,旨在将数据...

    DevExpress VCL 13.1.4(v2013vol1.4) 源码-例子-帮助-part2

    Q521783 - Ribbon Form - An AV occurs when restoring a minimized form whose non-client area is painted by the Ribbon if the form was minimized while displaying a hint for its window button Q526309 - ...

    DevExpress VCL 13.1.4(v2013vol1.4) 源码-例子-帮助-part1

    Q521783 - Ribbon Form - An AV occurs when restoring a minimized form whose non-client area is painted by the Ribbon if the form was minimized while displaying a hint for its window button Q526309 - ...

    Vue.js期末总复习

    Vue.js期末总复习 Vue.js是一款流行的JavaScript框架,用于构建用户界面。下面是Vue.js期末总复习的知识点总结: ...在上面的代码中,使用了v-if和v-else-if指令来实现条件判断,根据score数据的值来决定输出结果。

    BIos原代码《陈文钦》

    control will come here only if wake up is not needed ; $$$CORE0036+ jmp power_on_init power_on_init_end: in al,kb_stat_port ; if sys_flag bit is set test al,00000100b ; then soft reset else ...

    DevExpress VCL 12.2.6(v2012vol2.6) 源码-例子-帮助-part1

    Q490246 - Changing a bar item's Visible property when a form is being destroyed results in an AV Q489146 - Ribbon - A Ribbon tab group's Caption property does not apply to the group caption if this ...

    DevExpress VCL 12.2.6(v2012vol2.6) 源码-例子-帮助-part2

    Q490246 - Changing a bar item's Visible property when a form is being destroyed results in an AV Q489146 - Ribbon - A Ribbon tab group's Caption property does not apply to the group caption if this ...

    常用-发音特殊-较难拼写的单词.doc

    - **用法示例**: Her unselfishness was evident in her willingness to help others without expecting anything in return. #### 36. Celebrate [ˈselɪbreɪt] - **定义**: 动词,庆祝。 - **近义词**: ...

    50+Vue经典面试题详解,你值得收藏.docx

    <div v-for="item in items" v-if="item.isActive"> {{ item.name }} <!-- 推荐的做法 --> <ul v-if="shouldShowUsers"> <li v-for="item in activeItems">{{ item.name }} ``` 其中 `activeItems` 是一个计算...

Global site tag (gtag.js) - Google Analytics