`
Hooopo
  • 浏览: 328978 次
  • 性别: 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

 

分享到:
评论

相关推荐

    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 ...

    Sleeping_Dogs_SAVE_Games2you.rar_Just Cause_sds

    Just-Cause-2-everything-unlocked-and-nothing-destroyed-save-game.-Hardcore-mode

    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 - ...

    operation-destroyed-pony-web

    销毁小马网

    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 ...

    数位板压力测试

    This specification was developed in response to a perceived need for a standardized programming inter-face to digitizing tablets, three dimensional position sensors, and other pointing devices by a ...

    RSATool2.exe

    1) Select the correct number base for the value you want to check. 2) Type in or Paste the number in the Textbox for the Modulus (N). 3) Press the small 'Bits' button. This will show you the -exact...

    delphi 2007 第三方补丁

    - Fixed: TTabSheet could throw an access violation if no PageControl was assigned to it 2008-11-24: - Added fix for Show Component Caption IDE bug - Added fix for IDE Compiler opens all files in ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    For example, if your header file uses the File class in ways that do not require access to the declaration of the File class, your header file can just forward declare class File; instead of having ...

    Android代码-launcher

    Changing the bar color won't take full effect until all UserscriptActivity instances are destroyed (i.e. rotating the screen or restarting the app) Fixed in 4.1.5 Creating a new thread, then going to ...

    BCGControlBarPro.v12.00

    Just activate CBCGPVisualManager2010 to use these new themes in your application: CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager2010)); Please run BCGPMSOffice2007Demo, ...

    frame-wh:Efficiency comes from diligence. And in shortage in the play ground transportation into Si, and destroyed with。业精于勤而荒于嬉,行成于思而毁于随

    And in shortage in the play ground transportation into Si, and destroyed with。业精于勤而荒于嬉,行成于思而毁于随 -- 相关资料 程序员DD的blog log4j2 入门学习与总结 spring-boot默认配置 spring-boot-...

    vue中destroyed方法的使用说明

    主要介绍了vue中destroyed方法的使用说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

    AlphaControls 9.05 Version D7 -DXE6 full source

    最新9.05,包含源码,非DCU版,低调使用,你懂的。...Fixed error in TsSpeedButton when Action used and button is destroyed Improved switching of the TsSlider component TsSlider is improved in some skins

    VUE面试15题.docx

    包含问题答案 Vue.js 有哪些优点? 答案:Vue.js 的优点包括: - 易学易用 - 渐进式框架,可逐步应用于项目中 - 双向数据绑定 - 组件化开发 - 轻量级 ...3. Vue.js 如何实现双向数据...- destroyed(): 组件销毁之后调用

Global site tag (gtag.js) - Google Analytics