为什么@communities = Community.find_by_author(params [:author])不起作用?

时间:2013-02-01 18:27:58

标签: ruby-on-rails ruby-on-rails-3

我有一个名为Community的模型 我在社区表中有一个名为author的属性。

我有模特/ community.rb

然而,这不起作用。为什么呢?

@communities = Community.find_by_author(params[:author])

1 个答案:

答案 0 :(得分:1)

find_by将仅提供第一个匹配记录。因此,请使用where获取所有匹配的记录。

 Community.where(:author => params[:author])