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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 Mon, Oct 31, 2011 at 7:32 PM, Nikhil Goyal
<goyal.nikhil89-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:
> 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.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 1, 2:57 am, Everaldo Gomes <everaldo.go...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Oct 31, 2011 at 9:36 PM, Nikhil Goyal <goyal.nikhil89-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> > > On Nov 1, 2:57 am, Everaldo Gomes <everaldo.go...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. > >So, try using /[a-zA-Z0-9]/ as your constraint. I can''t remember a shortcut for alphanumeric, if there is one.> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.