Validation on Routes

I have a route that is something like this

match ‘/:token’ => ‘users#new’

This token is 8 digit alphanumeric. I want to add validations on it so
that it matches with the route only when there are 8 digits present in
token.

How can I do that.

Hi!

Try this:

match ‘:/:token’ => ‘users#new’ , constraints => { :token =>
/[a-zA-Z0-9]{8}/ }

There is \w in regexp that means letter, number and underscore
(accordlying
rubular.com) , but I don’t know if your token accepts underscores.

On Nov 1, 2:57am, Everaldo G. [email protected] wrote:

Hi!

Try this:

match ‘:/:token’ => ‘users#new’ , constraints => { :token =>
/[a-zA-Z0-9]{8}/ }

There is \w in regexp that means letter, number and underscore (accordlying
rubular.com) , but I don’t know if your token accepts underscores.

No there are no underscores. only alphabets and numbers.

On Mon, Oct 31, 2011 at 9:36 PM, Nikhil G.
[email protected]wrote:

There is \w in regexp that means letter, number and underscore
(accordlying
rubular.com) , but I don’t know if your token accepts underscores.

No there are no underscores. only alphabets and numbers.

So, try using /[a-zA-Z0-9]/ as your constraint. I can’t remember a
shortcut
for alphanumeric, if there is one.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs