How to change the default action for all the controllers?

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. :slight_smile:

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. :slight_smile:

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.

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.

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.

..

Method URLpath Action Helper

..

GET /people/1;edit edit edit_person_url(:id => 1)

This has been changed (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.

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. :slight_smile: