开发者

rails pagination for custom queries

I have the following custom query:

@initial_matches = Listing.find_by_sql(["SELECT * FROM listings WHERE industry = ? AND 开发者_高级运维years <= ? AND degree_type <= ?", current_user.industry, current_user.years, @highest_degree])

Any way to paginate the results?


Listing.where(:industry => current_user.industry).where(["years <= ?", current_user.years]).where(["degree_type <= ?", @highest_degree]).paginate

Better move this logic to scopes for this to look prettier and shorter.


Will_paginate works fine with basic Arrays.

In your controller:

@stuffs = %w(1 2 3 4 5 6 7 8 9 10).paginate(:page => params[:page], :per_page => 4)

In your view:

<% @stuffs.each do |stuff| %>
 <%= stuff %>
<% end  %>
<%= will_paginate @stuffs %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜