waldyr.ar
waldyr.ar

Reputation: 15194

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=>"/.+@.+\\..*/"}

Upvotes: 6

Views: 1903

Answers (1)

Kyle
Kyle

Reputation: 22258

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

Upvotes: 10

Related Questions