Rails:“标准化”方法用户输入的url?
我希望 Rails 应用程序中的用户能够在其个人资料中共享指向其个人网站的链接。很简单,我有一个名为 website
的列和一个他们可以填写以使其正常工作的文本字段。
但是,当我在视图中显示它时出现问题。如果我使用 link_to
帮助程序,则该人是否包含 http://
决定该网址是否有效。但是,如果我自动在前面加上 http://
,那么对于将其放入网址的用户,我会得到两次。
我确信这是一个相当常见的问题,但我找不到任何好的博客文章或解决该问题的问题。
我的问题是:您如何处理应用中用户输入的 URL?您会推荐什么作为最用户友好的方法来标准化最终存储在数据库中的网址?
谢谢!
I'd like Users in my Rails app to be able to share a link to their personal website in their profile. Simple enough, I have a column called website
and a text field they can fill in to make it work.
However, when I display this in a view there's a problem. If I use the link_to
helper then whether or not the person included the http://
determines whether or not the url will work. But, if I automatically prepend http://
then I get it twice for users who DID put it in their url.
I'm sure this is a fairly common problem, but I haven't been able to find any good blog posts or SO questions that address it.
My question is: How do you handle URL input from users in your apps? What would you recommend as the most user-friendly way to standardize the urls that end up being stored in the db?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您的问题,我可能会确保每当用户保存数据时,它都会使用如下所示的内容检查并修改(如果需要)网站属性。
If I understand your problem correctly I would probably make sure that whenever a user saves their data it checks and modifies (if needed) the website attribute using something like the following.