Douglas F Shearer

Rails Plugin: Will_Paginate_Search


THIS PLUGIN IS NOW DEPRECATED

The features provided by this plugin are now part of the Acts_as_indexed plugin it originally supported.

This plugin allows my acts_as_indexed indexed search plugin to interoperate with the will_paginate pagination plugin.

Install

Prerequisites

For this to work you’ll need the following two plugins…

Install will_paginate_search

./script/plugin install http://svn.douglasfshearer.com/rails/plugins/will_paginate_search

Setup

Follow through the instructions on setting up acts_as_search in the readme, and give the will_paginate readme a read over too.

Searching With Pagination

First argument is the search query (can be a GET variable or anything else), and after that it takes all the standard will_paginate arguments.

@images = Image.paginate_search 'girl', :page => 1, :per_page => 5

Other Stuff

Problems, Comments, Suggestions?

All of the above are most welcome. dougal.s@gmail.com

Credits

Douglas F Shearer

Donate

If you find this plugin useful, please consider a donation (Paypal) to show your support!

Tags

, , , , .

September 06 2007 14:24 | Posted in Coding | comments (8)
 

Comments


Gravatar

Chris

December 31 2007 04:37

I installed this plugin, will_paginate and your acts_as_indexed plugin. The pagination and acts_as_index work beautifully but, this one keep throwing me an error:

`per_page` setting cannot be less than 1 (0 given)

Using your example:
@images = Image.paginate_search 'girl', :page => 1, :per_page => 5

Modified to look like:
@results = Business.paginate_search params[:search][:for], :page => 1, :per_page => 5

Looking into the will_paginate_search.rb file I cannot seem to find the problem. Can't find it in will_paginate collections.rb on line 38 either...

Any ideas, I am a novice at ruby and ruby on rails?

Gravatar

Douglas F Shearer

January 11 2008 10:00

The plugin has now been updated to reflect the latest version of will_paginate, and prevent the error you were seeing.

Thanks for informing me of this.

Gravatar

Chris

January 12 2008 03:34

Thank you, kind sir! It works wonderfully!

Gravatar

Stephen Bartholomew

February 27 2008 20:53

Hey Douglas,

Loving your acts_as_indexed plugin, but I had a few problems getting will_paginate_search working.

The main issues seem to stem from the use of the wp_parse_options! method which as now changed to wp_parse_options in will_paginate.

I also had an issue where the :page and :per_page options were being passed to the find_with_index method causing an 'unknown keys' error from AR.

Anyway, I've pasted my changes here: http://pastie.cab...

These are just some quick patching, but hopefully they'll help!

Cheers,

Steve

Gravatar

D William

March 26 2008 13:46

When I try to go on next page (page 2) it says I have nil object when I didn't expect it.

Whats wrong?

Gravatar

Dan

April 22 2008 01:51

Douglas, these are incredibly useful plugins and I just wanted to say thank you.

Also Steve - your updates were great, fixed all my problems.

Thank you both.

Gravatar

Douglas F Shearer

April 22 2008 10:25

Thanks Dan.

Steve's patch has now been rolled into the plugin, so the previous issues should no longer be apparent.

Sorry it took so long, I missed that comment altogether.

Gravatar

Dan

April 30 2008 04:23

D William - I'm willing to bet that the issue you are running into is that your form is being submitted as a POST (Rails default) and not a GET. I had the same issue.

I changed my form tag from
<% form_tag :controller => 'browse', :action => 'search' do %> to <% form_tag({:action => 'search', :controller => 'browse'}, {:method => 'get'}) do %>

Now my form is being submitted as a GET and problem solved. I also recommend not using the default Rails form submit tag, <%= submit_tag "Search" -%> but an actual HTML tag, <input type="submit" value="Search" />. This will remove the useless Commit parameter from the URL.

Add Your Comments


(Required)

Your email address to get your Gravatar. Address itself is not shown.

(Include the http://)

(Required)

 

You Are Here


Douglas F Shearer

This is the homepage of Douglas F Shearer, a software developer and mountainbike racer. More…

Hire Me!


I'm available for hire. Ruby, Java and PHP work, both remotely (Worldwide) and locally (Scotland). Find out more or email me.

Flickr Latest


Stay Informed


What is RSS?

Categories


  1. Bike (83)
  2. Coding (82)
  3. Other (45)

Top Tags