Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the convention for ordering the controller actions in Rails?

Tags:

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?

like image 475
user80805 Avatar asked Jun 21 '11 07:06

user80805


People also ask

What is a controller action Rails?

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 .

How many standard controller actions does Rails provide?

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.

What decide which controller receives which request?

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.

What decides which controller receives which requests Ruby on Rails?

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.


1 Answers

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.

like image 181
Bitterzoet Avatar answered Dec 21 '22 04:12

Bitterzoet