开发者

Find first two records from collection

I want to retrieve the first two records from collection such that, collection is like:

@collect_firstnames = @name.firstnames

From this collection I want to fetch first two records...

I used开发者_开发百科 limit it is not working, :limit => 2


I take it that @name.firstnames is a has_many relationship. You need to pass the options to all:

@name.firstnames.all(:limit => 2)


You can use the :limit option like this:

@first_two = Name.find(:all, :limit => 2)

Edit

It's the same idea, assuming firstnames is a relationship (just like Swanand said below)

@first_two = @name.firstnames.all(:limit => 2)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜