Question

My Rails app uses usernames to get user's profile path

def to_param
  username
end

so if a username was licata, the profile page would be http://localhost:3000/licata.

Clearly, I need to specify certain words like help that cannot be used because I have a static page on the app with the route /help, so a username like this would create a conflict.

What's the most efficient way to do this?

Was it helpful?

Solution

Okay I believe I found the answer. I will post on here in case others have this question. Comment if better way or wrong.

validates :username, :exclusion => { :in => %w(foo bar) }

where foo and bar and so on are the words you can't use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top