【发布时间】:2012-12-21 11:48:31
【问题描述】:
有没有更优雅的方法来做到这一点:
widget.notes.where(:author_id => a).first.message= widget.notes.where(:author_id => a).first.message << "Potato"
例如,以下行不通:
widget.notes.where(:author_id => a).first.message << "Potato"
widget.notes.where(:author_id => a).first.message <<! "Potato"
分别不修改,或者返回错误(因为没有
<<!
操作员)
key:小部件是小部件的一个实例。小部件可以有注释。 Notes 有一个用于 :message 的 attr_accessible。 'a' 只是一个用户实例。
【问题讨论】:
-
(widget.notes.where(:author_id => a).first.message
-
那是因为它返回一个字符串...... derp......也许我应该为它写一个proc,因为它可能不是内置的
标签: ruby-on-rails ruby operators