Created
October 21, 2013 16:53
-
-
Save steveklabnik/7087076 to your computer and use it in GitHub Desktop.
Halp!
This file contains 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 Foo | |
has_many :tags | |
has_many :states | |
# q is hash: { "tags" => "ruby", "states" => "open" } | |
def self.search(q) | |
# wat do? | |
end | |
end | |
# search should return a relation that scopes everything to the terms | |
# the values 'ruby' and 'open' are in the 'name' attribute of the Tag and State model. |
Thanks so much everyone!
I'd love to know what you settle on. In a system of mine I do something like @subdigital's solution...
I prefer what you did @ https://gist.github.com/steveklabnik/6705873
I've tried like 20 different things with search module and stuff in the past year and never was satisfied by it. I think searching would be much easier to build in an abstract way if it would be possible to list the scopes for an ActiveRecord::Base. Is there a reason why it's not available?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@coreyword yes, the real search method takes a string, and i do some processing to get it into the hash form. figured i'd just ignore those details here though.