On my rap lyrics explanation website, every user has an associated "favorites" page at http://rapgenius.com/USERNAME
Because these favorites pages occupy the root namespace, I have to make sure that no one takes a username that I'm already using for something else. E.g.:
/songs
/lyrics
/users
/posts
How can I look up all top-level paths that have higher precedence than the /username
route (which is at the bottom of routes.rb
) at the time of user creation so I can prevent users from taking these reserved names?
Why not make things easier for yourself and simply do:
def validate
reserved = %w(songs lyrics users posts)
errors.add(:username, 'is not allowed') if reserved.include?(username)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With