Reputation: 8597
I've noticed that most actions have the same names, is it better this way? Is there a list of these names?
for example in a controller you would see:
def new
end
def create
end
def destroy
end
etc...
Do these specific action hold a purpose in Ruby on Rails?
Thanks
Upvotes: 1
Views: 1818
Reputation: 10684
Rails Rule of Convention over configuration applies here:
These actions are also useful for restful routes mapping, as many websites includes basic crud operations in them, So rails make it easy for developers to follow conventions and get rid of mapping routes by themselves.
It also depends on your needs, weather you want them or not or may be you need different names for those CRUD methods, in this case you have to specify routes manually for each action. In that case you are not following conventions as by introducing your own crud functions and increase your code size. Hope it sounds good to you now.
Upvotes: 2
Reputation: 4551
These are seven actions for CURD operations: index, new, create, show, edit, update and destroy. Sometime you need all of these and sometime not. If you are not using all these in any controller then you should remove the extra methods
Upvotes: 3
Reputation: 4850
Action names are associated with their view name. Show action provides for the show view, edit action for the edit view. The naming conventions allow rails to connect your view, model, controller (MVC). You can have custom action names, but its best to follow the rails CRUD. You don't even need all of the actions, sometimes you may only need a create and destroy....or whatever. For instance, you wouldn't want to rename 'new' to something you think is a better name...rails will be using that action and will be looking for an action named 'new'.
Active Record supplies a great deal of functionality to your Rails models for free,
including basic database CRUD (Create, Read, Update, Destroy) operations ....
Upvotes: 0
Reputation: 10147
Those are the seven default actions to support RESTful. These are one-to-one
mapping for CRUD. You can add your own action method.
More info: Rails routing
Upvotes: 3