Given a controller which implements all the CRUD actions: new
, create
, delete
, edit
, index
show
, update
, and also a few custom actions, is there any conventional (official or not) order these action should adhere to?
In the Rails architecture, Action Controller receives incoming requests and hands off each request to a particular action. Action Controller is tightly integrated with Action View; together they form Action Pack. Action Controllers, or just “controllers,” are classes that inherit from ActionController::Base .
Ruby on Rails defines seven standard controller actions can be used to do common things such as display and modify data. If you only want to create routes for specific actions, you can use :only to fine tune the resource route. This line maps URLs only to the Message controller's index and show actions.
When your application receives a request, the routing will determine which controller and action to run, then Rails creates an instance of that controller and runs the method with the same name as the action.
Routing decides which controller receives which requests. Often, there is more than one route to each controller, and different routes can be served by different actions.
The "official" order (as generated by the rails scaffold) is the following
index
show
new
edit
create
update
destroy
Although I always do index
show
new
create
edit
update
destroy
because I think it's a tad more logical to have the actual action that does the work, like create
and update
after the new
and edit
actions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With