Ruby on Rails
Wednesday, August 31, 2011
On Wed, Aug 31, 2011 at 12:01 PM, Conrad Taylor <conradwt@gmail.com> wrote:
On Wed, Aug 31, 2011 at 7:51 AM, 7stud -- <lists@ruby-forum.com> wrote:Conrad Taylor wrote in post #1019393:
> Bruno, I would recommend reading section 4.2 of the Rails routing guide:I read that, and I don't see how applying a regex to the id will help.
>
How about adding :show to the :except clause and doing this:
match '/:id' => 'users/show'
resources :users, :except=>[:destroy, :show]
If you apply the regex to the :id, then one can restrict the value ofthe :id to one or more digits. In the above, :id is simply a placeholderand can accept any value. Thus, the following should work for theoriginal poster:match '/:id' => 'users#show', :constraints => { :id => /[0-9]+/ }
A much better regular expression which matches a value of an :id should be something like the following:
match '/:id' => 'users#show', :constraints => { :id => /^[1-9]\d*/ }
Note: The above says that I have at least one digit >= 1 starting with the first digit.
-Conrad
resources :users, :except=> [ :destroy, :show ]
Good luck,-Conrad--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@googlegroups.com.
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.
--
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@googlegroups.com.
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment