I have an app where users can register their own personal url like so
- myapp.com/users-personal-url
I want to run through my rails config file and automatically grab the urls that are already in use, and iterate through these in a validation method to prevent users from reserving these urls. For example…
if in my routes file I have something like
match 'test' => 'courses#test'
resource :users
then users should not be able to register the “users” url or “test” url. So far I’ve found that I can grab all the routes inside a ruby class by using rake routes
But my string manipulation skills are failing me since I am a rails noob. Basically I need to substring the routes, place them in a collection and do the validation check. A pointer in the right direction or working code is appreciated. Thanks.
I don’t think there is any quick Rails way of doing what you would like to do in the routes.rb.
You would need to create custom validators in your model.
In the model that handles user generated URL submissions, add this validator.