I’ve mapped my users’ usernames off my root path to give them vanity
urls, (i.e. example.com/username), but if you capitalize any of the
letters of their username, rails throws an exception. It’s looking
for the case sensitive version of that name. So for instance,
example.com/username works, but example.com/USErNamE doesn’t.
I fixed the problem by putting this in my applications_controller.rb:
rescue_from NoMethodError do |exception|
if request.url != request.url.downcase
flash[:error] = “That doesn’t seem to exist.”
All it does is downcases the url, then tries that new url. I actually
found that solution on an answer to a stack overflow question that was
asking about case insensitive urls. Side note, stackoverflow doesn’t
seem to be case sensitive, like stackoverflow.com/QueStioNS still
displays the proper page and does no downcasing. However, I don’t
think they are built on rails, but twitter accomplishes this, too.
Like, twitter.com/eV still routes to the correct page with no
downcasing hack. It actually displays the upcased url but still
routes to the correct path. How are they doing this?
Or, how are you solving this?