'Convention Over Configuration in rails?

I am new to ruby on rails. I am going through its documentation and it says "Convention Over Configuration" What is this means ?



Solution 1:[1]

Ruby on Rails does a lot of things for you without the need to tell Rails how to do that. But this "magic" only works when you follow certain guidelines. "Convention Over Configuration" means as long as you follow certain conventions you do not need to add additional configuration.

For example, when you have a User model in your application then Rails assumes that it is defined in the file at app/models/user.rb. If that is the case then you do not need to require that file before using and Rails' autoloading feature will be able to do that for you. And Rails will assume that the user records will be stored in a database table named users. If that is the case no additional configuration will be needed and Rails will be able to load these records. But if the records are stored in a different table then you will have to tell Rails the new table name.

And there are more examples like that:

  • Defined routes in config/routes.rb route to specific controller methods when you follow a certain naming convention. If you do not then you have to configure how routes map ton controllers and their methods.
  • Rails picks certain views depending on the current controller and method name for rendering, but that only works when you name all files correctly.

Therefore my suggestion is: Do not try to fight Rails conventions. Rails magic only works when you follow Rails naming conventions. Using different names works but then you have to do a lot of additional configuration.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 spickermann