Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep track of reserved URLs (to enable vanity per-user URLs)

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?

like image 908
Tom Lehman Avatar asked Jan 24 '10 22:01

Tom Lehman


1 Answers

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
like image 127
John Topley Avatar answered Oct 20 '22 17:10

John Topley