Last active
August 29, 2015 13:56
-
-
Save angelsystem/9210211 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
#lib/startup_constraint.rb | |
class StartupConstraint | |
def matches?(request) | |
id = request.path.gsub("/", "") | |
Startup.find_by_slug(id) | |
end | |
end | |
#lib/user_constraint.rb | |
class UserConstraint | |
def matches?(request) | |
id = request.path.gsub("/", "") | |
User.find_by_slug(id) | |
end | |
end |
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
resources :startups | |
resources :users | |
# The priority is based upon order of creation: first created -> highest priority. | |
# See how all your routes lay out with "rake routes". | |
# You can have the root of your site routed with "root" | |
root 'pages#home' | |
constraints(Constrainer::UserConstraint.new) do | |
get '/:id', to: "users#show", as: 'short_user' | |
end | |
constraints(Constrainer::StartupConstraint.new) do | |
get '/:id', to: "startups#show", as: 'short_startup' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment