limit partial collection from view
I was trying to limit the rendering of partial collection, but I cannot change the controller or model (don't ask why, it's hard to explaint). So I have to limit it in view and only solution I could come up with is this
def suggested
@suggested ||= current_user.suggested_friends
end
<%= render :partial => 'layouts/three_panel_widgets/friend', :collection => suggested[0..3] %>
do you have any better ide开发者_运维问答as ?
If you are using rails 3, you can use suggested.limit(4)
. It will generate a SQL with LIMIT clause. This is a little bit better then using suggested[0..3]
.
<%= render :partial => 'layouts/three_panel_widgets/friend', :collection => suggested.limit(3) %>
精彩评论