Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed sql search for will_paginate 3.0 and activerecord 3.1 #54

Merged
merged 2 commits into from
Nov 16, 2011

Conversation

JangoSteve
Copy link
Contributor

Fixed sql-based search for will_paginate 3.0 and activerecord 3.1. I noticed there weren't any specs for this, and I don't really have time to write any specs for the search at the moment, unfortunately. But I figured at least this was a start (see inline notes for additional context).

With this and #53, I now have this app running on Heroku's Cedar stack (cc #45).

@@ -22,14 +22,16 @@ class SearchEngine::Sql < SearchEngine::Base
order = opts[:order] || "LOWER(#{self.table_name}.name) ASC"

pagination_options = {}
pagination_options[:page] = opts.delete(:page) if opts[:page].present?
pagination_options[:page] = opts[:page].present? ? opts.delete(:page) : 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting an error from will_paginate that "page is required", if it was nil, so I set a default of 1.

@@ -48,8 +50,17 @@ class SearchEngine::Sql < SearchEngine::Base
end

def self.search(query, options = {})
SearchEngine.searchable_models.map {|model|
model.to_s.constantize.search(query, options)
}.flatten
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was returning a flattened array instead of an object with a total_entries method (like what's returned by will_paginate), which was causing an error in the search view whenever there was more than 1 result.

reidab added a commit that referenced this pull request Nov 16, 2011
Fixed sql search for will_paginate 3.0 and activerecord 3.1
@reidab reidab merged commit 5e97649 into reidab:master Nov 16, 2011
@reidab
Copy link
Owner

reidab commented Nov 16, 2011

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants