Skip to content

Instantly share code, notes, and snippets.

@angelsystem
Last active August 29, 2015 13:56
Show Gist options
  • Save angelsystem/9210211 to your computer and use it in GitHub Desktop.
Save angelsystem/9210211 to your computer and use it in GitHub Desktop.
#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
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