Skip to content

Instantly share code, notes, and snippets.

@kozo002
Created July 26, 2012 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kozo002/3182589 to your computer and use it in GitHub Desktop.
Save kozo002/3182589 to your computer and use it in GitHub Desktop.
class QueryParameterConstraint
def initialize(*keys)
@keys = keys
end
def matches?(request)
result = false
@keys.each do |key|
result = request.query_parameters.has_key?(key)
break unless result
end
result
end
end
MyApp::Application.routes.draw do
resources :posts do
get '/', to: :search, as: :search, on: :collection,
constraints: QueryParameterConstraint.new(:q)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment