Skip to content

Instantly share code, notes, and snippets.

@leonid-shevtsov
Created October 31, 2011 14:14
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 leonid-shevtsov/1327575 to your computer and use it in GitHub Desktop.
Save leonid-shevtsov/1327575 to your computer and use it in GitHub Desktop.
get '/services/:id', :to => 'service_types#show', :as => :service_type, :constraints => SlugConstraint.new(ServiceType, :position => 2)
class SlugConstraint
def initialize(klass, options = {})
@klass = klass
@position = options.fetch(:position, 1)
end
def matches?(request)
@klass.exists?(:slug => request.path.split('/')[@position])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment