Ruby on Rails Rails Best Practices Convention Over Configuration


In Rails, you find yourself looking at controllers, views, and models for your database.

To reduce the need for heavy configuration, Rails implements rules to ease up working with the application. You may define your own rules but for the beginning (and for later on) it's a good idea to stick to conventions that Rails offers.

These conventions will speed up development, keep your code concise and readable, and allow you an easy navigation inside your application.

Conventions also lower the barriers to entry for beginners. There are so many conventions in Rails that a beginner doesn’t even need to know about, but can just benefit from in ignorance. It’s possible to create great applications without knowing why everything is the way it is.

For Example

If you have a database table called orders with the primary key id, the matching model is called order and the controller that handles all the logic is named orders_controller. The view is split in different actions: if the controller has a new and edit action, there is also a new and edit view.

For Example

To create an app you simply run rails new app_name. This will generate roughly 70 files and folders that comprise the infrastructure and foundation for your Rails app.

It includes:

  • Folders to hold your models (database layer), controllers, and views
  • Folders to hold unit tests for your application
  • Folders to hold your web assets like Javascript and CSS files
  • Default files for HTTP 400 responses (i.e. file not found)
  • Many others