如何处理自定义网址中的大写和小写字符? [英] How do I handle uppercase and lowercase characters in a custom url?

查看:108
本文介绍了如何处理自定义网址中的大写和小写字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让用户使用他们注册的用户名链接到他们的个人资料。

I want to let users have links to their profiles using their registered usernames.

我完全按照他们提供的方式存储用户名。

I store their username exactly how they give it.

我设置了匹配/:name的路由,然后使用find_by_name来获取它。我遇到的问题是,当您输入example.com/username时,该名称不起作用:Username。 (请注意大写/小写的区别)

I set up my routes to match /:name and then used find_by_name to get it. The problem I have is when you type in example.com/username it doesn't work the name: Username. (Note the uppercase/lowercase difference)

所以我的问题是如何忽略网址中的大小写?

So my question is how can I ignore case in urls?

推荐答案

您可以将小写的用户名 display_name 一起存储在他们给你的格式。然后,将任何输入转换为小写并与 username 匹配,并且仅将 display_name 用于显示:)

You can store the username downcased along with a display_name which is in the format they gave it to you. Then, downcase any input and match it with username and only use display_name for, well, display :)

如果需要,甚至可以从 /用户名 / DisPlAyName c>查找记录后。

If you wanted, you could even redirect to /DisPlAyName from /username after you look up the record.

这篇关于如何处理自定义网址中的大写和小写字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆