开发者

Limiting records in recursion

开发者 https://www.devze.com 2023-02-16 04:33 出处:网络
15:- 开发者_StackOverflow社区for findlist in @user.findlists 16:=findlist.name 17:%div 18:- for product in findlist.products
15:     - 开发者_StackOverflow社区for findlist in @user.findlists
16:       =findlist.name
17:       %div
18:       - for product in findlist.products
19:         = image_tag(product.photo.url(:small))

I am looking at line 18. Is there a way to limit findlist.products to only 3 records without putting some kind of counter?

I am using Rails 2.3.8


is limited a method in your model? you can always append a find method in rails 3 with limit(n)

so in your case if that is a find method

for product in findlist.products.limit(3)

if you're not using rails 3:

for product in findlist.products.find(:all, :limit => 3)
0

精彩评论

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