问题:
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 DestroyedAt 查找帮助?如果是一个 Bug ,请在GitHub上打开一个问题。安装将 destroyed_at gem 添加到 Gemfilegem 'destroyed_at'你可以在每个模块中
- 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....
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 ...
Just-Cause-2-everything-unlocked-and-nothing-destroyed-save-game.-Hardcore-mode
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 - ...
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 - ...
销毁小马网
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 ...
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 ...
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 ...
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...
- 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 ...
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 ...
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 ...
Just activate CBCGPVisualManager2010 to use these new themes in your application: CBCGPVisualManager::SetDefaultManager (RUNTIME_CLASS (CBCGPVisualManager2010)); Please run BCGPMSOffice2007Demo, ...
And in shortage in the play ground transportation into Si, and destroyed with。业精于勤而荒于嬉,行成于思而毁于随 -- 相关资料 程序员DD的blog log4j2 入门学习与总结 spring-boot默认配置 spring-boot-...
主要介绍了vue中destroyed方法的使用说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
最新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.js 有哪些优点? 答案:Vue.js 的优点包括: - 易学易用 - 渐进式框架,可逐步应用于项目中 - 双向数据绑定 - 组件化开发 - 轻量级 ...3. Vue.js 如何实现双向数据...- destroyed(): 组件销毁之后调用