Created
October 31, 2011 14:14
-
-
Save leonid-shevtsov/1327575 to your computer and use it in GitHub Desktop.
This file contains 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
get '/services/:id', :to => 'service_types#show', :as => :service_type, :constraints => SlugConstraint.new(ServiceType, :position => 2) |
This file contains 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
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