Topic: ajax search with pagination
First of all, I fixed my previous search problem with a change to the routes.rb file.
I had it set such that:
blog.connect 'blog', 'blog', :action => 'list'
blog.connect 'blog/:id', :action => 'show', :id => 'blog.id'
blog.connect 'blog/search', :action => 'search'
I guess when i typed in the browser: localhost:3000/blog/search, it got some id error. So I switched the middle line to being 'blog/show/:id' and the search worked. I guess the routes took the 'search' as an id, and couldnt find that blog id. If anyone knows really why, then let me know.
Back to my problem, my search in blog_controller.rb looks like this:
@posts = Post.find(:all, :conditions => ["lower(title) like ?", "%" + params[:search].downcase + "%"])
if @posts.size > 0
render :partial => "post", :collection => @posts
render :text => "<li>No results found.</li>", :layout => false
how can i associate this with pagination? I have my list method (also in the blog_controller.rb)looking like this:
@post_pages, @posts = paginate :post, :per_page => 10, :order_by => "created_at DESC"
@post = Post.find(:first)
I'm using observe_field to update the posts from the list in my list.rhtml view and post only the posts that are shown from the search. However, once the search is initiated, the search results aren't paginated anymore. How can I paginate the search results?