Rails 3.2.8 imはkaminariを使用してページ付けを行っていますが、エラーが発生し続けます:undefined method `current_page'for#
のposts_controller.rb
def index
@posts = Post.order(:created_at).page(params[:page])
end
のviews/posts/index.html.erb
<%= paginate @posts %>
何が問題なのか?
Rails 3.2.8 imはkaminariを使用してページ付けを行っていますが、エラーが発生し続けます:undefined method `current_page'for#
のposts_controller.rb
def index
@posts = Post.order(:created_at).page(params[:page])
end
のviews/posts/index.html.erb
<%= paginate @posts %>
何が問題なのか?
コードを次のように変更してみてください
@posts = Post.order(:created_at)
Kaminari.paginate_array(@posts).page(params[:page]).per(10)
または
@posts = Post.order(:created_at).page(params[:page]).per(10)
Kaminari.paginate_array(@posts).page(params[:page]).per(10)
そして 10 の代わりに任意の数字を書くことができます => .per(10) ビューコードは同じままにします。
will_paginate デフォルトにはページネーションが付属していますがActiveRecord::Relation、配列の場合はこの特定のメソッドを使用する必要があります。