# Probably common n00b question: Default id

**URL:** <https://www.ruby-forum.com/t/probably-common-n00b-question-default-id/131196>\
**Category:** Rails\
**Created:** [March 6, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/probably-common-n00b-question-default-id/131196 "2008-03-06T21:13:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [March 6, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/probably-common-n00b-question-default-id/131196/1 "2008-03-06T21:13:43Z")

</div>

Hi, I’m new to Rails but I develop in PHP somtimes. I figured that the  
best way to learn Rails is to create a simple CMS. While I understand  
the basics of ruby and rails, one issue has caught me: how can I set a  
default ID for an action?

Here is my code for the index action in my pages controller:

def index

```
@page = Page.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.xml { render :xml => @page }
end

```

end

However, when I load [http://localhost:3000/pages](http://localhost:3000/pages) , I get a message:

Couldn’t find Page without an ID

How can I make my application assume a default ID of 1 if none is  
provided?

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [March 6, 2008, 9:37pm UTC](https://www.ruby-forum.com/t/probably-common-n00b-question-default-id/131196/2 "2008-03-06T21:37:25Z")

</div>

On Mar 6, 2008, at 12:12 PM, Tom S. wrote:

> How can I make my application assume a default ID of 1 if none is  
> provided?

I’m not sure that’s what you want to do. In Rails 2.0.x, the mapping is:

GET =\> action =\> index =\> list of items  
GET /id =\> action =\> show =\> individual item identified by id

Run rake routes to see how your HTTP verbs map to your controller/  
action pairs.

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [March 6, 2008, 10:28pm UTC](https://www.ruby-forum.com/t/probably-common-n00b-question-default-id/131196/3 "2008-03-06T22:28:50Z")

</div>

Maybe I should look at some other examples

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [March 8, 2008, 8:34pm UTC](https://www.ruby-forum.com/t/probably-common-n00b-question-default-id/131196/4 "2008-03-08T20:34:56Z")

</div>

Yeah, that’s good, thanks!

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [March 6, 2008, 10:55pm UTC](https://www.ruby-forum.com/t/probably-common-n00b-question-default-id/131196/5 "2008-03-06T22:55:20Z")

</div>

Tom S. wrote:

> Maybe I should look at some other examples

def pages  
if params[:id]  
@hotel = Hotel.find(params[:id])  
else  
@hotel = Hotel.find(:all)  
end

end

HOpe it can help you.

```auto
Reinhart Ariando
WEB: Teapoci.Blogspot.com
YM : Booking2Heaven
MSN: removed_email_address@domain.invalid

```
