On Wed, Aug 31, 2011 at 3:07 PM, Bruno Meira <[email protected]> wrote:
> Hi 7stud,
> I wanted a URL like that: /users/:id, where :id could only be one or
> more integers, actually the user id.
> I don't have in mind any case that this line could'nt be resolve.
> Could you give me an example?
> Thx ;D
>
>
If this is the case, then I would recommend just simply using the following
and deal with the error case within the action:
resources :users
For example,
def show
@user = User.find( params[:id] ) # This will generate an exception if
the value of the params[:id] doesn't exist (i.e. AR::RecordNotFound).
...
end
def show
@user = User.find_by_id( params[:id] ) # This will return nil if the
value of the params[:id] doesn't exist.
...
end
In both cases above, you'll have to deal with the case where the record does
not exist. For example, this would be in the form of
a 'Page Not Found' for your site or something similar. In short, I would
just use resources as resources and provide a good user
experience when an error does occur. However, there are cases when
constrains work well but I don't think this is a good use case
for it.
Good luck and have fun,
-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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.