# How to change the default action for all the controllers?

**URL:** <https://www.ruby-forum.com/t/how-to-change-the-default-action-for-all-the-controllers/137136>\
**Category:** Rails\
**Created:** [May 9, 2008, 8:41am UTC](https://www.ruby-forum.com/t/how-to-change-the-default-action-for-all-the-controllers/137136 "2008-05-09T08:41:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![muyayi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@muyayi](https://www.ruby-forum.com/u/muyayi)\
**Post date:** [May 9, 2008, 8:41am UTC](https://www.ruby-forum.com/t/how-to-change-the-default-action-for-all-the-controllers/137136/1 "2008-05-09T08:41:15Z")

</div>

I am new to rails. I am trying to study the structure of rails. And  
I am wondering, where is the default action for all the controllers  
(i.e. index) defined. How does rails know that when no action is  
defined in URL it just loads index as the default action? I assume  
that this must be in some of the libraries, but anybody who could tell  
me where. Thanks a lot. 🙂

---

<div class="post-metadata">

**Author:** ![muyayi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@muyayi](https://www.ruby-forum.com/u/muyayi)\
**Post date:** [May 9, 2008, 8:03pm UTC](https://www.ruby-forum.com/t/how-to-change-the-default-action-for-all-the-controllers/137136/2 "2008-05-09T20:03:04Z")

</div>

muyayi wrote:

> I am new to rails. I am trying to study the structure of rails. And  
> I am wondering, where is the default action for all the controllers  
> (i.e. index) defined. How does rails know that when no action is  
> defined in URL it just loads index as the default action? I assume  
> that this must be in some of the libraries, but anybody who could tell  
> me where. Thanks a lot. 🙂

If you’re looking at RESTful rails, its just versions of GET, PUT, POST,  
DELETE requests:

Method URL path Action Helper  
GET /people index people\_url  
GET /people/1 show person\_url(:id =\> 1)  
GET /people/new new new\_person\_url  
GET /people/1;edit edit edit\_person\_url(:id =\> 1)  
PUT /people/1 update person\_url(:id =\> 1)  
POST /people create people\_url  
DELETE /people/1 destroy person\_url(:id =\> 1)

Browsers cannot issue an http DELETE, so Rails fakes this out with a  
POST request with an additional hidden parameter named ‘\_method’ whose  
value is ‘delete’. When Rails receives a \_method parameter, it ignores  
the real http method, and substitutes the value of \_method as the  
request type.

I’d list the reference back to the site I poached this from if I could  
remember what it was.

---

<div class="post-metadata">

**Author:** ![muyayi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@muyayi](https://www.ruby-forum.com/u/muyayi)\
**Post date:** [May 11, 2008, 7:18am UTC](https://www.ruby-forum.com/t/how-to-change-the-default-action-for-all-the-controllers/137136/3 "2008-05-11T07:18:35Z")

</div>

I believe the default is set in:  
C:\ruby\lib\ruby\gems\1.8\gems\actionpack-2.0.2\lib\action\_controller  
\resources.rb,  
but… You better really know what you are doing if you muck with  
this.

---

<div class="post-metadata">

**Author:** ![muyayi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@muyayi](https://www.ruby-forum.com/u/muyayi)\
**Post date:** [May 12, 2008, 2:37pm UTC](https://www.ruby-forum.com/t/how-to-change-the-default-action-for-all-the-controllers/137136/4 "2008-05-12T14:37:36Z")

</div>

[http://dev.rubyonrails.org/ticket/11181](http://dev.rubyonrails.org/ticket/11181)

> change default action paths for “new” and “edit”, in an environment or directly  
> in the route definition (because on some languages, coherent action  
> names  
> would depend on the resource name):
> 
> config.action\_controller.resources\_path\_names = { :new =\> ‘nuevo’, :edit =\> ‘editar’ }
> 
> In the route definition:
> 
> map.resource :schools, :as =\> ‘escuelas’, :path\_names =\> { :new =\> ‘nueva’ }

As for the index method, why would you want to rename this? It’s just  
internal.

> On May 9, 11:03 am, Ar Chron [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> …
> 
> > Method URLpath Action Helper  
> > …  
> > GET /people/1;edit edit edit\_person\_url(:id =\> 1)

This has been changed ([http://dev.rubyonrails.org/changeset/6485](http://dev.rubyonrails.org/changeset/6485)) over a  
year ago. It is now

GET /people/1/edit

because the semicolon was a bad idea to begin with. Stuff after a  
semicolon  
isn’t recognized as part of the URL by some browsers. Unfortunately many  
tutorials still have this old syntax which isn’t recognized by Rails 2.

---

<div class="post-metadata">

**Author:** ![muyayi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c5a1d2/32.png) [@muyayi](https://www.ruby-forum.com/u/muyayi)\
**Post date:** [May 12, 2008, 9:56pm UTC](https://www.ruby-forum.com/t/how-to-change-the-default-action-for-all-the-controllers/137136/5 "2008-05-12T21:56:59Z")

</div>

Not intending to start a war here but I thought that the semicolon was  
a good idea. By the http spec it is a non-breaking (ie., not  
introducing another level) part of the url. In that regard is was  
more expressive of RESTful routes because ‘edit’ (from the previous  
post) is something that you’re doing to the instance identified on the  
same level; now it looks like edit is one level down from the object  
(that is, you’re looking for the edit object scoped to some person).

The problem was that several browsers were written only to recognize  
semicolons in query strings, which was a subset of the appropriate/  
permissible urls they could have recognized. Their implementation  
made perfect sense on a pragmatic level: it reflected the generally  
accepted use even if it was not the defined standard.

Go figure… you follow the rules and you’re labeled the bad boy.  
Next thing you know they’ll try to implement all the defined HTTP  
verbs or something crazy like that. 🙂
