Created
July 29, 2011 13:47
-
-
Save Marchino/1113832 to your computer and use it in GitHub Desktop.
Search with squeel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def to_query_params | |
words = [] | |
self.split(/\W/).each do |word| | |
words << "%#{word}%" | |
end | |
return words | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search_string = params[:q] || "" | |
words = search_string.to_query_params | |
@collection = current_user.questions.joins{item(RareBook).outer} | |
.joins{item(Comicbook).outer} | |
.joins{item(ModernBook).outer} | |
.joins{item(Photo).outer} | |
.joins{item(Autograph).outer} | |
.joins{item(Postcard).outer} | |
.joins{item(Print).outer} | |
.joins{item(Newspaper).outer} | |
.joins{bookshop.profile.outer} | |
.where do | |
(item(RareBook).title.like_any words) | | |
(item(Comicbook).title.like_any words) | | |
(item(ModernBook).title.like_any words) | | |
(item(Photo).title.like_any words) | | |
(item(Autograph).title.like_any words) | | |
(item(Postcard).title.like_any words) | | |
(item(Print).title.like_any words) | | |
(item(Newspaper).title.like_any words) | | |
(bookshop.profile.name.like_any words) | | |
(id.eq search_string) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment