5

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

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.

My routing match is as follows:

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.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
griffithben
  • 115
  • 9

2 Answers2

8
match "confirm/:code/:email" => "confirm#index", :email => /.*/

Also it would be better to set get method here, I think

get "confirm/:code/:email" => "confirm#index", :email => /.*/
fl00r
  • 82,987
  • 33
  • 217
  • 237
5

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 => /.*/ }

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.

rav_kr
  • 434
  • 8
  • 16
mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • @griffithben: This problem drove me nuts when I found it. The rails developers assume that you'll only ever want to pass an ID number in a RESTful URL for some shortsighted reason. – mu is too short Apr 24 '11 at 02:50
  • No. The reason is because you can specify `format`. As far as you can use a number of formats: js, pdf, xml etc – fl00r Apr 24 '11 at 02:56
  • @fl00r: I noted that in the answer. My comment is saying that the Rails developers almost always only use numeric IDs (rather than human readable things like email addresses or domain names) in their RESTful URLs so they don't see the default route parsing behavior as a problem. – mu is too short Apr 24 '11 at 03:28