Skip to content

Instantly share code, notes, and snippets.

@leemour
Forked from araslanov-e/gist:5895283
Created July 3, 2013 09:25
Show Gist options
  • Save leemour/5916621 to your computer and use it in GitHub Desktop.
Save leemour/5916621 to your computer and use it in GitHub Desktop.
Routing constraint
# app/constraints/photo_constraint.rb
class PhotoConstraint
def initialize
@types = Photo::TYPES
end
def self.matches?(request)
@types.include?(request.path_parameters[:type])
end
end
# config/routes.rb
get 'photos/:type', to: 'photos#index', constraints: PhotoConstraint.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment