【发布时间】:2014-03-14 10:17:20
【问题描述】:
有没有更好的方法来编写这段代码?这对我来说似乎有点冗长。
我正在使用 sunspot SOLR,stored() 方法返回 nil 或值数组,如果第一个值存在,我总是想要它,或者只打印一个空字符串。
<td><%= search_result.stored(:seo_title).first() if search_result.stored(:seo_title).present? %></td>
<td><%= search_result.stored(:title).first() if search_result.stored(:title).present? %></td>
<td><%= search_result.stored(:publish_at).first() if search.result.stored(:publish_at).present? %></td>
【问题讨论】:
标签: ruby-on-rails ruby coding-style