I am trying to apply pagination on my rails application using Kaminari. I also include a simple search form based on Railscast Episode # 37 . When I try to apply the kaminari page and for each method, I get the error "undefined method page". Below is the code I'm using.
posts_controller.rb
def index @posts = Post.search(params[:search]).page(params[:page]).per(2) end
post.rb
def self.search(search) if search find(:all, conditions: ['title || body LIKE ?', "%#{search}%"], order: "created_at DESC") else find(:all) end end
index.html.erb
<%= paginate @posts %>
When I delete the pagination, the search works fine. When I delete the search, pagination works fine. I just can't use both of them and correctly execute the code function. Please let me know if there is something in my code that I am missing that makes it work incorrectly.
Aaron source share