带有句点(或句号)的 Rails 查询字符串. [英] Rails query string with a period (or full stop).

查看:18
本文介绍了带有句点(或句号)的 Rails 查询字符串.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试了解 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 的 params 哈希中得到的只是 'bob'.我把 gmailcom 之间的 . 去掉了,因为这会导致匹配根本不起作用.

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 使其不试图对 :email 包含的内容变得聪明.

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屋!

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