1
我正在寫一個行動涉及協會組成的長鏈,喜歡的東西:檢查在協會的長鏈的所有腦幹軌
@featured_image = @content_page.content_tree_item.children.first.featured_images.first
我想如果有這些協會得到@featured_image = nil
不存在。我可以這樣做:
@featured_image = @content_page.content_tree_item.children.first.featured_images.first rescue nil
但在rescue
籠罩整個鏈條似乎hackish的,可能掩蓋了其他問題。是否有一個「軌道路」,或至少一種更好的方式,要做到這一點,只有捕捉到一個協會的非所有腦幹?
呀,可能。無論如何,謝謝你指出我正確的方向。 – skinnynerd 2013-04-21 21:23:04