alamodey
alamodey

Reputation: 14953

Rails pagination error

I'm using the will_paginate plugin and I get the following error only when I'm running on a server rather than locally:

undefined method `total_pages' for []:Array
Extracted source (around line #8):

5:  <% session[:page] = params[:page] %>
6:  <h2>Previous Scenario</h2>
7: <% end %>
8:  <%= will_paginate @scenarios, :next_label => 'Older', :prev_label => 'Newer' %>
9: <div class="box">
10: <% for scenario in @scenarios %>
11:     <% @created = scenario.created_at %>

Any ideas?

Upvotes: 0

Views: 1809

Answers (2)

jonty
jonty

Reputation: 470

Somehow, @scenarios is an ordinary Array for you and it can't be from Scenario.paginate() method because that one always returns a WillPaginate::Collection object.

Upvotes: 1

Ghoti
Ghoti

Reputation: 2380

Does your controller have the other half of the equation, e.g.

@scenario = Scenario.paginate(:page => params[:page]||1)

Alternatively I think you might have a plugin on the server side that is converting your Active Record set into a plain array. I'd need a bit more info to look at that.

Upvotes: 1

Related Questions