Created
May 17, 2013 18:08
-
-
Save dustinsmith1024/5600855 to your computer and use it in GitHub Desktop.
A way to filter a route based on query params. You can also make the module a class and then initialize it to pass in whatever you want.
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
module QueryParamConstraint | |
extend self | |
def matches?(request) | |
request.query_parameters["view"] == request.path_parameters[:action] | |
end | |
end | |
MyPortal::Application.routes.draw do | |
root to: 'home#index' | |
get "/foo" => "people#show", :constraints => QueryParamConstraint | |
get "/foo" => "people#index", :constraints => QueryParamConstraint | |
resources :people, only: [:index, :show] do | |
resources :facts, only: :index | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requests would look like.
We could set up a different query_param for nested routes