Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put an email address in url on Rails

I want to invite people who passes their email inside an url like this:

localhost:3000/invite_me/[email protected]

I tried this match but it isn't working.

match "/invite_me/:email" => "application#invite_me",
    :constraints => { :email => '/.+@.+\..*/' }

I'm getting the following error:

No route matches [GET] "/invite_me/[email protected]"

rake routes output:

root  /                           application#index
  /invite_me/:email(.:format) application#invite_me {:email=>"/.+@.+\\..*/"}
like image 743
waldyr.ar Avatar asked Oct 25 '12 15:10

waldyr.ar


1 Answers

Your constraint needs to be an actual regular expression and not a string

match "/invite_me/:email" => "application#invite_me",
    :constraints => { :email => '/.+@.+\..*/' }

Should be

match "/invite_me/:email" => "application#invite_me",
    :constraints => { :email => /.+@.+\..*/ }
like image 55
Kyle Avatar answered Oct 17 '22 04:10

Kyle