Ruby Forum Ruby on Rails > How to change the default action for all the controllers?

Posted by muyayi (Guest)
on 09.05.2008 08:41
(Received via mailing list)
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. :)
Posted by Ar Chron (railsdog)
on 09.05.2008 20:03
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.
Posted by Ruby Freak (Guest)
on 11.05.2008 07:18
(Received via mailing list)
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.
Posted by Ix Quic (Guest)
on 12.05.2008 14:37
(Received via mailing list)
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 <rails-mailing-l...@andreas-s.net> 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) 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.