# Existence of params\[:id\]

**URL:** <https://www.ruby-forum.com/t/existence-of-params-id/136692>\
**Category:** Rails\
**Created:** [May 5, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/existence-of-params-id/136692 "2008-05-05T16:32:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@anthony](https://www.ruby-forum.com/u/anthony)\
**Post date:** [May 5, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/existence-of-params-id/136692/1 "2008-05-05T16:32:57Z")

</div>

ok, i’m sure I have forgotten or missing something, i hope you guys  
can help:

if a user types :controller/edit/1, then he gets to edit the object  
with the :id of 1.

If he only types in :controller/edit I want it to redirect him  
somewhere else.

How do I test for the existence of params[:id] in an if statement. Or  
is there a better way to accomplish this?

Thanks

---

<div class="post-metadata">

**Author:** ![anthony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/49beb7/32.png) [@anthony](https://www.ruby-forum.com/u/anthony)\
**Post date:** [May 5, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/existence-of-params-id/136692/2 "2008-05-05T16:44:42Z")

</div>

Anthony wrote:

> ok, i’m sure I have forgotten or missing something, i hope you guys  
> can help:
> 
> if a user types :controller/edit/1, then he gets to edit the object  
> with the :id of 1.
> 
> If he only types in :controller/edit I want it to redirect him  
> somewhere else.
> 
> How do I test for the existence of params[:id] in an if statement. Or  
> is there a better way to accomplish this?
> 
> Thanks

Well, assuming that your routes.rb file is set up the way it should you  
should be able to get at the :id in your controller, that is unless you  
have some kind of filter at work in your controller. But to test for the  
existence of :id use params[:id[.blank? or params[:id].nil?

-S
