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.
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.
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.
On May 9, 11:03 am, Ar Chron [email protected] 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.
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.