I think it's better to submit the parameter :total_entries
to method paginate
:
@posts = Post.paginate(:page => params[:page], :per_page => 30,
:total_entries => 1000)
will_paginate will generate links only for the number of pages needed to show 1000 results.
You can also verify that the requested page belongs to the interval:
if params[:page].to_i * 30 <= 1000
@posts = Post.paginate(:page => params[:page], :per_page => 30,
:total_entries => 1000)
end
Moreover, by submitting the parameter :total_entries
, you avoid the sql COUNT query that will_paginate normally runs to retrieve the total number of entries.