Rails查询字符串,带有句点(或句号)。 [英] Rails query string with a period (or full stop).
问题描述
我目前正在尝试了解RoR。我向控制器传递了两个字符串。一个是随机的十六进制字符串,另一个是电子邮件。该项目用于在数据库上进行简单的电子邮件验证。我遇到的问题是当我输入以下内容来测试页面时:
I am currently trying to get a handle on RoR. I am passing in two strings into my controller. One is a random hex string and the other is an email. The project is for a simple email verification on a database. The problem I am having is when I enter something like below to test my page:
http://signup.testsite.local/confirm/da2fdbb49cf32c6848b0aba0f80fb78c/bob.villa@gmailcom
所有我都在:email
是'bob'
。我在 gmail
和 com
之间留了。
All I am getting in my params hash of :email
is 'bob'
. I left the .
between gmail
and com
out because that would cause the match to not work at all.
我的路由匹配如下:
match "confirm/:code/:email" => "confirm#index"
对于我所需要的看起来似乎很简单。我很难弄清楚这笔交易是什么,以及如何真正找到答案。
Which seems simple enough for what I need. I am having a hard time trying to figure out what the deal is and really how to even search for an answer. Any help or guidance would be greatly appreciated.
推荐答案
您的问题是Rails试图解释。 villa @ gmailcom
作为格式规范(例如 .html
或 .json
)。 AFAIK,标准的解决方法(或至少是我使用的一种方法)是将其添加到您的路线中:
Your problem is that Rails is trying to interpret .villa@gmailcom
as a format specification (such as .html
or .json
). AFAIK, the standard work around (or at least the one I use) is to add this to your route:
:requirements => { :email => /.*/ }
这会欺骗Rails不要对:电子邮件
包含。
This tricks Rails into not trying to be clever about what :email
contains.
对于找不到 @或 @的内容,我并不感到惊讶。没有任何用处。
I'm not surprised that you couldn't find anything, googling for "@" or "." doesn't do anything useful.
这篇关于Rails查询字符串,带有句点(或句号)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!