Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created October 21, 2013 16:53
Show Gist options
  • Save steveklabnik/7087076 to your computer and use it in GitHub Desktop.
Save steveklabnik/7087076 to your computer and use it in GitHub Desktop.
Halp!
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.
@pier-oliviert
Copy link

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