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
redirect_to request.url.downcase
else
flash[:error] = "That doesn't seem to exist."
redirect_to root_path
end
end
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?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.