Reputation: 5430
I am trying to search my posts item with pagination. I am doing like this..
@posts = Post.search(params[:search]).paginate(page: params[:page],:per_page => 5)
But it showing NoMethodError
undefined method `paginate' for #<Array:0x9a93f08>
I don't know where i am wrong. Please help
Upvotes: 1
Views: 1666
Reputation: 5430
I just change my code
@posts = Post.search(params[:search]).paginate(page: params[:page],:per_page => 5)
to this
@posts = Post.paginate(page: params[:page],:per_page => 5).search(params[:search])
Now it works fine :)
Upvotes: 3
Reputation: 22296
I will advise you to use Kaminari instead. As you can see by the Readme there's one section on to paginate Arrays. Also make sure you read the Kaminari recipes where is an example on paginate Arrays.
Upvotes: 0
Reputation: 118271
params[:search])
gives you an array. And Array don't have paginate
method, so errors thrown up. Use p params[:search]).inspect
to see the same.
Upvotes: 0