在Rails視圖,可以使用try
只輸出是否存在於數據庫中的值,例如如何在Rails中鏈接try()和scoped to_s()?
@model.try(:date)
並且人們可以鏈改掉如果,例如,輸出需要作爲字符串
@model.try(:date).try(:to_s)
但是如果我需要調用scoped格式呢?我試過
@model.try(:date).try(:to_s(:long))
@model.try(:date).try(:to_s).try(:long)
這是什麼正確的語法?什麼是更多解釋的好參考?
由於
現貨!謝謝! – 2012-04-28 04:41:07