Michael Nana
Michael Nana

Reputation: 1987

NoMethodError in StaticPagesController#home

rails newbie here. I'm on the last section of the tutorial and I just can't believe I get stuck here.

I get a noMethodError in static_pages_controller that says this

undefined method `paginate' for #<Array:0x3c22aa0>

 

class StaticPagesController < ApplicationController
  def home
    if signed_in?
      @micropost  = current_user.microposts.build
      @feed_items = current_user.feed.paginate(page: params[:page])
    end
  end

  def help
  end

  def about
  end

  def contact
  end
end

I have the will_paginate gem installed and the paginate function works on the other parts of the code.

I'm on Michael Hartl Rails tutorial section 11.3.4.

It would be great if you guys could help me out.

Upvotes: 1

Views: 480

Answers (1)

jvnill
jvnill

Reputation: 29599

will_paginate by default does not support pagination for arrays. in order to support this, you need to require an additional file. create a file called will_paginate_array.rb inside config/initializers. then add the following

require 'will_paginate/array'

restart your server and you should be able to paginate arrays.

Upvotes: 2

Related Questions