문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top