【发布时间】:2018-12-05 12:15:43
【问题描述】:
假设有一个模型称为 Comments。不,我们这样做@comments = Comment.where(name: 'John')。接下来我们做comment = Comment.find_or_create_by(...)。 Rails 中有没有办法将comment 加入@comments?对于数组我可以做 @comments << comment 但我想要 activeRecords...
@comments.inspect 返回"#<ActiveRecord::Relation []>"
我正在使用 Rails 5.1.3
谢谢,安德烈亚斯
【问题讨论】:
-
你不是说
@comments.inspect返回"#<ActiveRecord::Relation []>"吗? -
你是对的,谢谢。已更新。
标签: ruby-on-rails activerecord scope